110121 JS Syntax

조다희·2021년 11월 1일
0

.push() : pushs the element in the end of an array
.pop() : pops the element in the end of an array
.shift(): removes the first element of an array
.unshift(): adds the element at the beginning of the array.

Global vs Local

the local variable takes precedence over the global variable.

arr.push(item);

var removed = arr.shift(item);

return removed; // Changed
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modified
console.log("After: " + JSON.stringify(testArr));
profile
블로그 옮김 https://daheejo.tistory.com/

0개의 댓글