Skip to content

Instantly share code, notes, and snippets.

@SergeyLipko
Created April 28, 2017 20:22
Show Gist options
  • Save SergeyLipko/a6ab03dc5a82d2b1c00c5a0b6741a122 to your computer and use it in GitHub Desktop.
Save SergeyLipko/a6ab03dc5a82d2b1c00c5a0b6741a122 to your computer and use it in GitHub Desktop.
// ля получения значений подобно циклу for...of, можно использовать метод
let arr = [ 3, 5, 7 ];
arr.foo = "hello";
arr.forEach(function (element, index) {
console.log(element); // выведет "3", "5", "7"
console.log(index); // выведет "0", "1", "2"
});
// или при помощи Object.keys()
Object.keys(arr).forEach(function (element, index) {
console.log(arr[element]); // выведет "3", "5", "7", "hello"
console.log(arr[index]); // выведет "3", "5", "7"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment