Answers for "es6 array loop"

8

javascript loop through array of objects es6

/* new options with IE6: loop through array of objects */

const people = [
  {id: 100, name: 'Vikash'},
  {id: 101, name: 'Sugam'},
  {id: 102, name: 'Ashish'}
];

// using for of
for (let persone of people) {
  console.log(persone.id + ': ' + persone.name);
}

// using forEach(...)
people.forEach(person => {
 console.log(persone.id + ': ' + persone.name);
});
// output of above two methods
// 100: Vikash
// 101: Sugam
// 102: Ashish


// forEach(...) with index
people.forEach((person, index) => {
 console.log(index + ': ' + persone.name);
});
// output of above code in console
// 0: Vikash
// 1: Sugam
// 2: Ashish
Posted by: Guest on May-04-2020
1

loop through arrays in es6

var sandwiches = [
	'tuna',
	'ham',
	'turkey',
	'pb&j'
];

sandwiches.forEach(function (sandwich, index) {
	console.log(index);
	console.log(sandwich);
});

// returns 0, "tuna", 1, "ham", 2, "turkey", 3, "pb&j"
Posted by: Guest on April-23-2020
1

for of loop in es6

let colors = ['Red', 'Blue', 'Green'];
for (let color of colors){
	console.log(color);
}
Posted by: Guest on April-25-2020
0

ex: javascript loop array

<div class="slider">
  <div class="slide" id="slide-1"></div>
  <div class="slide" id="slide-2"></div>
  <div class="slide" id="slide-3"></div>
  <div class="slide" id="slide-4"></div>
  <div class="slide" id="slide-5"></div>
</div>
Posted by: Guest on July-06-2021
0

ex: javascript loop array

- Settings
local targets = {
   ["Immortal Bone Lord"] = CFrame.new(418.845795, 301.952881, -87.0185776);
   ["The Bone Lord"] = CFrame.new(1252.41711, 634.311829, 1296.42688);
   ["The Currupted Bone Lord"] = CFrame.new(889.415344, 134.573166, -796.304321);
   ["The Bone Lord's Son"] = CFrame.new(-3207.92969, -22.9497356, -46.0395622);
   ["Togarmah Bone Lord"] = CFrame.new(-1655.9231, 272.089569, -953.731018);
   ["Titan Volcanus"] = CFrame.new(-307.934082, 468.891418, 1169.38232);
   ["Titan Fulmen"] = CFrame.new(-320.062347, 468.891418, 1735.12219);
   ["Titan Glacies"] = CFrame.new(-328.104004, 468.891418, 2224.52539);
   ["Titan Terra"] = CFrame.new(-332.205444, 468.891418, 2689.16235);
   ["Titan Venenum"] = CFrame.new(-1880.53491, 362.692108, 2665.90332);
   ["Titan Inanis"] = CFrame.new(-308.255737, 492.378632, 3282.45044);
   ["Horseless Headman"] = CFrame.new(1111.41504, 530.446716, -1707.05554);
   ["GOD"] = CFrame.new(2298.39258, 303.93866, -892.633179);
   ["DEVIL"] = CFrame.new(2251.33643, 462.782562, -445.206116);
   ["3tcyGDh8a57eKYasvw2haG9tWAr8qpZsXc8WGwT17s"] = CFrame.new(1668.94775, 241.221237, 109.730064);
   ["Neon Boss"] = CFrame.new(-151.036209, 772.825745, 452.247253);
   ["The Sun"] = CFrame.new(885.015381, 321.131439, 2312.57153);
   ["Rezokar, Ex-Dev"] = CFrame.new(1279.10474, 613.814575, 2009.51587);
   ["The Loyal King"] = CFrame.new(-1080.84448, 1290.51184, 368.369141);    
}

-- UI Library
local library = loadstring(game:HttpGetAsync('https://pastebin.com/raw/edJT9EGX'))()
local window = library:CreateWindow("TP To Bosses")
window:AddLabel({text="Click To TP A Boss"})
for i,v in pairs(targets) do
   window:AddButton({text=i,callback=function()
       game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = v
   end})
end
library:Init()
Posted by: Guest on June-20-2021
0

es6 for-of loop

for (let itme of list) {
  ...
}
Posted by: Guest on September-20-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language