Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 11
    Worth noticing that arrName[3] does not append, it overrides. Commented Sep 10, 2018 at 22:40
  • It add the element to the existing array not over ride, Ex: let arrName = ['xxx', 'yyy', 'zzz']; arrName.splice(1, 0,'aaa', 'bbb', 'ccc'); after print the arrName Commented Sep 12, 2018 at 18:49
  • If arrName has more than 3 elements you are overriding the 3rd, not appending. Or am I looking this at the wrong way? Commented Sep 12, 2018 at 18:51
  • If we insert an element on the middle, it shift the next element not overide. Please specify your problem, what you need. Take an array(example) and what you need on the output. plz comment me Commented Sep 12, 2018 at 18:56
  • 2
    @Srikrushna arrName[3] = 'newName1'; will append if the array has only 3 elements. If there is an element in index 3, this will be replaced. If you want to append at end, it is better to use arrName.push('newName1'); Commented Nov 14, 2019 at 8:24

lang-js