By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!yes i have read it.Can you explain a little clearly what you want to know. I could not understand anything? Did you read this - JavaScript for Loop
// For of loop used for Array
const arr = ["Apple", "Mango", "Orange", "Banana"];
for(let x of arr){
console.log(x);
}
// For in loop used for Object
const obj = {
Ap: "Apple",
Mg: "Mango",
Or: "Orange",
Bn: "Banana"
}
for(let n in obj){
console.log(obj[n]);
}
// For in loop used for Object
const obj = {
Ap: "Apple",
Mg: "Mango",
Or: "Orange",
Bn: "Banana"
}
// For in loop getting keys and values
for(let b in obj){
console.log("Key is: " + b + " and Value is: " + obj[b]);
}
- for - loops through a block of code a number of times
- for/in - loops through the properties of an object
- for/of - loops through the values of an iterable object
- while - loops through a block of code while a specified condition is true
- do/while - also loops through a block of code while a specified condition is true
Built-in iterables
String, Array, TypedArray, Map, and Set are all built-in iterables, because each of their prototype objects implements an @@iterator method.
function isIterable(obj) {
// checks for null and undefined
if (obj == null) {
return false;
}
return typeof obj[Symbol.iterator] === 'function';
}
["t", "h", "i", "s", " ", "i", "s", " ", "n","o","t", " ","i","t","e","r","a","b","l","e"]
and from Mozilla (and others) we know that any string, array, typedarray, map, or set are iterable.Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.