xxxxxxxxxx
let array = [1,2,3] // makes your array
array[0] // returns first element of your array.
xxxxxxxxxx
data = [{
id: 1,
name: "Pedro"
}, {
id: 2,
name: "Pedro"
}, {
id: 3,
name: "Pedro"
}]
data.find(item => item.name == "Pedro") // Return { id: 1, name: "Pedro" }
data.findLast(item => item.name == "Pedro") // Return { id: 3, name: "Pedro" }
xxxxxxxxxx
var items = ["Item 1", "Item 2", "Item 3"];
var firstItem = typeof items[0] !== "undefined" ? items[0] : null;
console.log(firstItem);
xxxxxxxxxx
let mylist = ['one','two','three','last'];
mylist[0],mylist[1],mylist[2],mylist[3];//this is called indexing and slicing in python
//in javascript it called getting elements in array
xxxxxxxxxx
// Assuming the array is already defined
let array = [1, 2, 3, 4, 5];
// Method 1: Using array indexing
let firstElement = array[0];
console.log(firstElement); // Output: 1
// Method 2: Using Array.prototype.shift()
let shiftedElement = array.shift();
console.log(shiftedElement); // Output: 1
console.log(array); // Output: [2, 3, 4, 5]
xxxxxxxxxx
let array = ["a", "b", "c", "d", "e"];
// Both first1 and first2 have the same value.
let [first1] = array;
let first2 = array[0];
xxxxxxxxxx
$arr = array( 4 => 'apple', 7 => 'orange', 13 => 'plum' );
echo reset($arr); // Echoes "apple"
xxxxxxxxxx
const [first, second, third] = ["Laide", "Gabriel", "Jets"];
console.log(first); // Output: Laide
console.log(second); // Output: Gabriel
console.log(third); // Output: Jets