access array number 2 and 3 to be in one string array

  • A+
Category:Languages

How to have output :

ID: 0001 Name: Mike Birthday: London 21/05/1989 Hobby: Reading 

My below code is undefined, I want the array city + date to be together in the birthday.

My code was not, check my code below :

var input = [                 ["0001", "Mike", "London", "21/05/1989", "Reading"],                 ["0002", "Sara", "Manchester", "10/10/1992", "Swimming"],                 ["0003", "John", "Kansas", "25/12/1965", "Cooking"],                 ["0004", "Dave", "Nevada", "6/4/1970", "going to gym"]             ];  var data = ["ID: ", "Name: ", "Birthday: ", "Hobby: "];     for(var i = 0 ; i <= input.length ; i++){   for(var j = 0  ; j <= input.length ; j++){   for(var i = 0 ; i <= data.length; i++){   console.log(data[i] + input[j][i])     };   }; };

Is that any suggestion to fix this logic ? I just want to use the loop, for this.

 


Try this

//contoh input var input = [                 ["0001", "Mike", "London", "21/05/1989", "Reading"],                 ["0002", "Sara", "Manchester", "10/10/1992", "Swimming"],                 ["0003", "John", "Kansas", "25/12/1965", "Cooking"],                 ["0004", "Dave", "Nevada", "6/4/1970", "going to gym"]             ];  var data = ["ID: ", "Name: ", "Birthday: ", "Hobby: "];  // for(var i = 0 ; i < data.length ; i++){ //   console.log(data[i]);  var k = 0; for(var i = 0 ; i < input.length ; i++){    for(var j = 0; j <= data.length ; j++){        if(j == 2 ){           console.log(data[k] + input[i][j]+ " " + input[i][j+1]);           j++;        }        else           console.log(data[k] + input[i][j]);        k++;    }k=0; }

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: