Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

splice()

/"removes any number of consecutive elements from anywhere in an array."/
let array = ['today', 'was', 'not', 'so', 'great'];

array.splice(2, 2);
// remove 2 elements beginning with the 3rd element
// array now equals ['today', 'was', 'great']
Comment

splice

//Example 1:

//Remove 1 element at index 3
let myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon']
let removed = myFish.splice(3, 1)

//Result
// myFish is ["angel", "clown", "drum", "sturgeon"]
// removed is ["mandarin"]

//Example 2:

//Remove 1 element at index 2, and insert "trumpet"
let myFish = ['angel', 'clown', 'drum', 'sturgeon']
let removed = myFish.splice(2, 1, 'trumpet')

//Result
// myFish is ["angel", "clown", "trumpet", "sturgeon"]
// removed is ["drum"]
Comment

splice

const sing = "I am a disco dancer"
console.log(sing.slice(0,5))// I am
Comment

PREVIOUS NEXT
Code Example
Javascript :: nested array in json 
Javascript :: javascript how-do-i-check-whether-a-checkbox-is-checked-in-jquery 
Javascript :: yamljs 
Javascript :: function expression javascript 
Javascript :: import file in chrome extension 
Javascript :: how to make a field not required with joi 
Javascript :: what is shortest javascript program 
Javascript :: install node specific version ubuntu 
Javascript :: how to use react fragment 
Javascript :: javascript sort multi-dimensional array by column 
Javascript :: Towers of Hanoi, Iterative and Recursive 
Javascript :: faker js uuid example 
Javascript :: flask sqlalchemy json 
Javascript :: array.fill() in javascript 
Javascript :: react video srcobject 
Javascript :: webpack dev server 
Javascript :: jquery scroll to element toggle menu item 
Javascript :: try catch 
Javascript :: tagged templates 
Javascript :: changing map style react-leaflet 
Javascript :: javascript string objects 
Javascript :: tailwind rn yarn install 
Javascript :: ngif react 
Javascript :: directive multiple input 
Javascript :: in compare method why we taking a and b for sorting in javascript 
Javascript :: mail testing 
Javascript :: what are devtools 
Javascript :: how to pass props to another component 
Javascript :: useEffect react dependency 
Javascript :: random message in discord.js 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =