Sunday, November 28, 2021

Difference between splice() and slice() in javascript array

slice()- returns a shallow copy of a portion of given array .
ex:
var a=['j','u','r','g','e','n'];
console.log(a.slice(3,5));
output: ["g","e"]

splice() - returns the removed elements from an array . It effects the orginal array .
var a=['j','u','r','g','e','n'];
console.log(a.splice(3,5));
output:["g", "e", "n"]
orginal array:['j','u','r']

No comments:

Post a Comment

Fluent interface pattern

 public class UserConfigurationManager {     private String userName;     private String password;     private UserConfigurationManager() { ...