js const fruits = ['apple', 'banana']; fruits.push('orange'); console.log(fruits); // Output: ['apple', 'banana', 'orange']
js const fruits = ['apple', 'banana', 'orange']; const lastFruit = fruits.pop(); console.log(fruits); // Output: ['apple', 'banana'] console.log(lastFruit); // Output: 'orange'
js const fruits = ['apple', 'banana', 'orange']; const firstFruit = fruits.shift(); console.log(fruits); // Output: ['banana', 'orange'] console.log(firstFruit); // Output: 'apple'
js const fruits = ['banana', 'orange']; fruits.unshift('apple'); console.log(fruits); // Output: ['apple', 'banana', 'orange']
js const fruits = ['apple', 'banana', 'orange']; fruits.splice(1, 1, 'kiwi', 'mango'); // Removes 1 element at index 1 and adds 'kiwi' and 'mango' console.log(fruits); // Output: ['apple', 'kiwi', 'mango', 'orange']
js const numbers = [1, 2, 3, 4, 5]; numbers.fill(0, 1, 4); // Fills from index 1 to 4 with 0 console.log(numbers); // Output: [1, 0, 0, 0, 5]
js const numbers = [5, 3, 8, 1]; numbers.sort(); // Sorts numbers as strings by default console.log(numbers); // Output: [1, 3, 5, 8]
js const numbers = [1, 2, 3, 4]; numbers.reverse(); console.log(numbers); // Output: [4, 3, 2, 1]
js const fruits = ['apple', 'banana', 'orange']; fruits.splice(1, 1); // Removes 1 element at index 1 console.log(fruits); // Output: ['apple', 'orange']
js const numbers = [1, 2, 3, 4, 5]; numbers.copyWithin(0, 3); // Copies elements from index 3 to 0 console.log(numbers); // Output: [4, 5, 3, 4, 5]
위 내용은 JS에서는 어떤 배열 방법을 사용해야 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!