Question:Briefly describe JavaScript core Array method splice() with an example. 

Answer Array.splice() is a method used to insert, delete, and substitute values in array elements. The method has three arguments, start, delete, and data. The starting position specifies where the new value (data) is to be inserted and where deletions begin. If no deletions are specified, the splice() method has the effect of inserting an element and value into an array.Example:
var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
 stackWork.splice(1,0,"Fred");  
 document.write(stackWork);
Output: Lenny,Fred,Harold,Mary,Jean,Sal 

+ Report
Total Preview: 1076
Briefly describe JavaScript core Array method splice() with an example.
Copyright © 2024. Powered by Intellect Software Ltd