1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Re-mapping an array.

Discussion in 'JavaScript' started by Lammie71, Jul 15, 2022.

  1. #1
    Can anyone show me how I can re-map an array using the following criteria.

    For example I have two arrays:
    
    arr1 = [201,188,123,140,172,142,85,731];
    arr2 = [3,0,7,1,2,4];
    Code (JavaScript):
    I wish to create a new array using the values on arr2 as the indexes on arr1.
    For example arr1[arr2[0]] would be 140 and so on.

    Final output of the new array would [140,201,731,188,123,172];

    For a small amount of numbers I could use push but arr1 and arr2 could potentially have a lot of numbers.

    Thanks in advance.
     
    Lammie71, Jul 15, 2022 IP
  2. Lammie71

    Lammie71 Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #2
    Hi, I have managed to work it out myself - below is what I have done.

    
    function myFunction(num) {
    return num * 10;
    }
    
    arr1 = [201,188,123,140,172,142,85,731,73,92,104,23];
    arr2 = [3,0,7,1,2,10];
    
    arr3 = arr2.map(bbc);
    document.write("*** "+arr3);
    
    Code (JavaScript):
    Cheers.
     
    Lammie71, Jul 15, 2022 IP
    qwikad.com likes this.