javascript - How to use an array element as an index of another array -


i've 2 arrays in javascript code. want use element of array x index array y.

you can see i've numbers in array x, there possible , easy way can it.

<script>     var x = [1,2,3,4,6]     var y = ["kin","kim","jong","ving","gon","von","rick"] </script> 

like

 y+x[4]  //(not code idea) 

must print "rick".

i tried

 y+x[4] //i know that's stupid 

but not working. please provide answer in javascript.

you should read mdn - array more.

var x = [1,2,3,4,6] var y = ["kin","kim","jong","ving","gon","von","rick"] var index = x[4]; //6 console.log(y[index]); // @ index 6, value "rick" 

or

y[x[4]] // "rick" 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -