get value like 1 12 of a array where value is like const a = 123 in javascript
To get the values like [1], [1,2] from an array in JavaScript, you can use the slice() method. Here's an example:
const a = [1, 2, 3];
const result1 = a.slice(0, 1); // [1]
const result2 = a.slice(0, 2); // [1, 2]
console.log(result1); // Output: [1]
console.log(result2); // Output: [1, 2]
In this example, slice() method is used to extract a portion of the array. The first parameter is the starting index (inclusive) and the second parameter is the ending index (exclusive). By specifying different index ranges, you can extract different subsets of the array
AI 优化版
原文地址:https://www.cveoy.top/t/topic/hDX1 著作权归作者所有。请勿转载和采集!