Insert, Remove और Join करना
table library items add और remove करती है और इन्हें एक string में जोड़ती है।
In this page:
Insert, Remove, और Join करना
table.insert(t, v) append करता है और table.insert(t, pos, v) एक position पर insert करता है, बाद के items को ऊपर shift करते हुए। table.remove(t) last item remove करके return करता है, और table.remove(t, pos) एक position पर remove करता है, items को नीचे shift करते हुए। table.concat(t, sep) strings या numbers को एक separator से जोड़ता है।
Note:
एक empty table पर table.remove nil return करता है और कोई error raise नहीं करता।
उदाहरण: Inserting, removing and joining
local t = {"a", "b", "c"}
table.insert(t, "d")
table.insert(t, 1, "start")
print(table.concat(t, ","))
print(table.remove(t), table.remove(t, 1))
print(table.concat(t, ","), #t)
print(table.remove({}))
-- Output:
-- start,a,b,c,d
-- d start
-- a,b,c 3
-- nil
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- table.insert में position और value arguments swap करना
- tables या booleans वाली एक table पर table.concat call करना
- एक forward loop के अंदर items remove करना और elements skip करना
चैप्टर सारांश
- table.insert append करता है या एक position पर insert करता है
- table.remove removed item return करता है
- table.concat एक separator से जोड़ता है
- Remove करते वक्त backwards loop करें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: