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
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):