Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add new element by index js

const arr = [ 1, 2, 3, 4 ];
arr[5] = 'Hello, world!';

console.log(arr); // [ 1, 2, 3, 4, <1 empty item>, 'Hello, world!' ]
console.log(arr.length); // 6
Source by learn.coderslang.com #
 
PREVIOUS NEXT
Tagged: #add #element #index #js
ADD COMMENT
Topic
Name
4+7 =