Array Splicing In Javascript Code Example


Example 1: javascript splice

let arr = ['foo', 'bar', 10, 'qux'];  // arr.splice(<index>, <steps>, [elements ...]);  arr.splice(1, 1);			// Removes 1 item at index 1 // => ['foo', 10, 'qux']  arr.splice(2, 1, 'tmp');	// Replaces 1 item at index 2 with 'tmp' // => ['foo', 10, 'tmp']  arr.splice(0, 1, 'x', 'y');	// Inserts 'x' and 'y' replacing 1 item at index 0 // => ['x', 'y', 10, 'tmp']

Example 2: splice javascript

let arrDeletedItems = arr.splice(start[, deleteCount[, item1[, item2[, ...]]]])

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?