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.

array input value how to replace decode value as Output using JavaScript code

Discussion in 'JavaScript' started by deepu1023, Nov 21, 2019.

  1. #1
    Hi

    I have dynamic input array variable value
    Decode values
    1-->Java
    2-->HTML
    3-->SQL
    4-->PHP
    5-->DOTNet
    6-->JavaScript
    7-->Oracle

    input values
    arrstrval =1,2,5,4,7

    but my output should be like below
    arrstrval =Java,HTML,DOTNet,PHP,Oracle

    Can any one help me Please
     
    deepu1023, Nov 21, 2019 IP
  2. harsimarriar96

    harsimarriar96 Member

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #2
    const a = ['Java','HTML', 'SQL', 'PHP', 'DOTNet', 'Javascript', 'Oracle'];
    
    const strval = [1,2,5,4,7];
    
    let newarr = [];
    
    for(i = 0; i < strval.length; i++) {
      newarr.push(a[strval[i]-1]);
    }
    
    console.log(newarr);
    Code (JavaScript):
    It will log your desired output.

    By the way, I think the better way to do this is with objects.

    const obj = { id: 1, name: 'Java' }
    
    Code (JavaScript):
     
    harsimarriar96, Nov 21, 2019 IP
  3. deepu1023

    deepu1023 Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3

    Thanks for your assistance and Thanks a Lot :)
     
    deepu1023, Nov 21, 2019 IP