Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript add item by index

// Be careful!

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: #javascript #add #item #index
ADD COMMENT
Topic
Name
4+1 =