How to loop on array

i have some code

Blockquote const target_number = [“6285155046155”,“628112212120”,“628075155046157”];

const target_nama = [“Ramdan”,“Ikhsan”,“vandi”];

const target_link = [“","link ikhsan”,“link vandi”];

var message = `
invation link : ${target_link[[0]]}

name  "${target_nama[[0]]}" `;

and how to loop and display that data in an array

Hello @dizzyshop :wave: Welcome to :glitch: Glitch!

There is multiple ways you can loop through content, the first one, and probably the easiest one is called a for of loop, which is as simple as the following:

const numbers = [ 1, 2, 3, 4, 5, 6, 7 ];

for (let n of numbers)

Firstly an array (numbers) is created, containing a bunch of numbers. Secondly, a for look is defined with a statement saying that let n is equal to each one of numbers. This is also a so-called iteration loop.

The second way of doing looping through an array is by using the array’s boundaries (their length). It goes like this:

const names = [ "Christy", "Verdell", "Chaya", "Geneva", "Chadwick" ];

for (let index = 0; i < names.length; i++)
  const value = names[index];

In the above example, a list of names is defined. The example used a loop that defines three statements.

for ( statement1; statement2; statement3 )
{ ... }

Whereas statement1 executes only once before looping, statement2 which defines the condition executing the code block, and statement3 which is executed (every time) the code block has been executed.

There are however other ways to loop through an array to display or change information of what’s inside it. For instance, which changes the contents of the elements stored inside the array. An example of this could be to make an array that shows who first came through the finish line.

// This is an ordered array of the names who crossed the finish line.
const finishList = [

// We'll iterate over the list using
// and change the values to show the following:
// ${name} crossed the line and was the ${index} to cross.

const list =
  (value, index) => `${value} crossed the line and`
                  + `was the ${index} to cross.`

// Now to make things a little bit easier for ourselves,
// we'll use Array.join() to make it all into a string
// with the new values on a separate line.

const str = list.join("\n");

// John crossed the line andwas the 0 to cross.
// Jane crossed the line andwas the 1 to cross.
// Bob crossed the line andwas the 2 to cross.
// Alice crossed the line andwas the 3 to cross.
1 Like

ES66 introduces a new method for arrays, array.forEach(), which will loop through an array, and each element of the array can represented using a callback object.

const finishList = [

// iterate over the values with array.forEach()
// use the callback variable provided

finishList.forEach(name => {
   console.log(name); // it will loop through the array and print all the elements of the array