Looping Array in Javascript: In this post we will loop through array value using for loop.
//javascript for loop array..
const anil = [
'Anil',
'Singh',
2021 - 1990,
'programmer',
['ram', 'shyam', 'sohan'],
true,
]
for (let i = 0; i < anil.length; i++) {
console.log(anil[i], typeof anil[i]);
}
// Start loop and add value in Blank array..
const anil = [
'Anil',
'Singh',
2021 - 1990,
'programmer',
['ram', 'shyam', 'sohan'],
true,
];
const valueType = [];
for (let i = 0; i < anil.length; i++) {
console.log(anil[i]);
// valueType[i] = typeof anil[i] OR
valueType.push(typeof anil[i]);
}
console.log(valueType);
// For loop for array calculate ages
const years = [1970, 1975, 1985, 1990, 1995];
const age = [];
for (let i = 0; i < years.length; i++) {
age.push(2021 - years[i]);
}
console.log(age);
0 comments
Post a Comment