This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [ 'foo', 'bar', 'baz' ]; | |
let removedElement; | |
// Elimina la primer instancia de 'bar' | |
if ( array.indexOf( 'bar' ) > -1 ) { | |
removedElement = array.splice( array.indexOf( 'bar' ), 1 ); | |
} | |
// [ 'foo', 'baz' ] | |
console.log( array ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = [ 'foo', 'bar', 'baz' ]; | |
// Elimina el primer elemento del array | |
const removedElement = array.shift(); | |
// [ 'bar', 'baz' ] | |
console.log( array ); | |
// 'foo' | |
console.log( removedElement ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = [ 'foo', 'bar', 'baz' ]; | |
// Elimina el último elemento del array | |
const removedElement = array.pop(); | |
// [ 'foo', 'bar' ] | |
console.log( array ) | |
// 'baz' | |
console.log( removedElement ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = [ 'foo', 'bar', 'baz' ]; | |
// Empezando en la posición 1, elimina los dos siguientes elementos | |
const removedElement = array.splice( 1, 2 ); | |
// [ 'foo' ] | |
console.log( array ); | |
// [ 'bar', 'baz' ] | |
console.log( removedElement ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = [ 'foo', 'bar', 'baz' ]; | |
// Empezando en la posición 1, elimina el siguiente elemento | |
const removedElement = array.splice( 1, 1 ); | |
// [ 'foo', 'baz' ] | |
console.log( array ); | |
// [ 'bar' ] | |
console.log( removedElement ); |
NewerOlder