← Back to Lua Course | Chapter 4: Tables | Lesson 5 of 7

Insert, Remove और Join करना

table library items add और remove करती है और इन्हें एक string में जोड़ती है।

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

lua
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
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. table.insert में position और value arguments swap करना
  2. tables या booleans वाली एक table पर table.concat call करना
  3. एक forward loop के अंदर items remove करना और elements skip करना
चैप्टर सारांश
  • table.insert append करता है या एक position पर insert करता है
  • table.remove removed item return करता है
  • table.concat एक separator से जोड़ता है
  • Remove करते वक्त backwards loop करें

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.