xxxxxxxxxx
//create an array
let numbers = [ 11 , 13 , 15 , 17]
//you can use loop like this
for(let i = 0;i<numbers.length;i++) {
console.log(numbers[i])
}
xxxxxxxxxx
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
xxxxxxxxxx
const language = ['Javascript', 'HTML,CSS', 'ReactJS']
// toString : Biến Array thàng 1 chuỗi
language.toString()
// join : Biến Array thành 1 chuỗi bằng cách đưa ra điểm chung
language.join()
// pop : Xoá element cuối array và trả về phần tử đã xóa
language.pop()
// push : Thêm 1 hoặc nhiều element cuối array và trả về độ dài mới của array
language.push('NodeJS')
// shift : Xóa đi phần tử ở đầu array
language.shift()
// Thêm 1 hoặc nhiều element đầu array và trả về độ dài mới của array
language.unshift('NodeJS')
// splice : Hàm dùng để xóa các phần tử trong array,
// Và thêm 1 hoặc nhiều element
// Tham số 1 vị trí bắt đầu đặt trỏ chuột xóa
// Tham số thứ 2 xóa bao nhiêu element (if 0 thì ko xóa)
// Tham số thứ 3
language.splice(1, 0, 'JAVA')
// concat : Dùng để nói 2 mảng với nhau
// language.concat(language2)
// slice : Dùng để cắt 1 hoặc nhiều element của array
// Dùng để copy array, có 2 tham số giống splice
language.slice(0, 2)
xxxxxxxxxx
Input: nums = [-4,-1,0,3,10]
Output: [0,1,9,16,100]
Explanation: After squaring, the array becomes [16,1,0,9,100].
After sorting, it becomes [0,1,9,16,100].
xxxxxxxxxx
//create an array:
let colors = ["red","blue","green"];
//you can loop through an array like this:
//For each color of the Array Colors
for (color of colors){
console.log(color);
}
//or you can loop through an array using the index:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
xxxxxxxxxx
// this is an array
var days = ["sunday","mondey","tuesday","wednesday"]
//here you can call arrays items using index number inside squar bracket
console.log(day[0])
console.log(day[1])
console.log(day[2])
xxxxxxxxxx
const array = [1, 2, 3, true, null, undefined];
console.log(array);
// expected output
// 1, 2, 3, true, null, undefined