0

I try to fill an array randomly. I have an rows array:

rows = ['1','0','2','1','3'];

and columns array:

columns = ['0','0','1','2','3'];

and a button array:

butArray = [];

I initialized button array. What I try to

printArr[rows[i]][columns[i]] = butArray[i];

How exactly should I use loop here?

13
  • 4
    What exactly are you trying to achieve? Commented Nov 16, 2016 at 7:15
  • There are no random indexes Commented Nov 16, 2016 at 7:16
  • @Rajesh I try to locate buttons dynamically, I take the rows , columns, button values from user and according to this I print the buttons on the screen. Commented Nov 16, 2016 at 7:17
  • @Weedoze Normally I take rows and columns from user. Commented Nov 16, 2016 at 7:18
  • 1
    @EminÇiftçi Your question is not clear. Please show us what is inside butArray[] and what is the final result Commented Nov 16, 2016 at 7:20

1 Answer 1

1

I think you are looking for this.

https://plnkr.co/edit/1J2VWX0yCIWITQp6Yax8?p=preview

// Code goes here

function myclick(){
  console.log("cds")
  rows = ['1','0','2','1','3'];
  columns = ['0','0','1','2','3'];
  butArray = ['qwe','qwe','qewe','qew','qwe'];//some values
  var printArr = [];
  for(var i=0 ; i<columns.length ; i++){
    if(printArr[rows[i]] == undefined)
    printArr[rows[i]] = []
    printArr[rows[i]][columns[i]] = butArray[i];

  }
  console.log(printArr);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, that is what I exactly looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.