Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

deepumay15

Programmer
Jul 27, 2009
1
CA
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
 
Hi

Assuming you not need compatibility with Explorer 8 and older, a simple [tt]Array.map()[/tt] call should do it.
Here you can see how I used it in the browser's console :
Code:
[silver]13:51:16.714[/silver] ⇨ [purple]language_list[/purple] = [[fuchsia]undefined[/fuchsia], [navy]'Java'[/navy], [navy]'HTML'[/navy], [navy]'SQL'[/navy], [navy]'PHP'[/navy], [navy]'DOTNet'[/navy], [navy]'JavaScript'[/navy], [navy]'Oracle'[/navy]]
[silver]13:51:16.747[/silver] ⇦ ‣ [COLOR=steelblue]Array[/color][gray](8)[/gray] [COLOR=steelblue][[/color] [gray]undefined[/gray], [fuchsia]"Java"[/fuchsia], [fuchsia]"HTML"[/fuchsia], [fuchsia]"SQL"[/fuchsia], [fuchsia]"PHP"[/fuchsia], [fuchsia]"DOTNet"[/fuchsia], [fuchsia]"JavaScript"[/fuchsia], [fuchsia]"Oracle"[/fuchsia] [COLOR=steelblue]][/color]

[silver]13:51:30.152[/silver] ⇨ [purple]arrstrval[/purple] = [[navy]1[/navy], [navy]2[/navy], [navy]5[/navy], [navy]4[/navy], [navy]7[/navy]]
[silver]13:51:30.179[/silver] ⇦ ‣ [COLOR=steelblue]Array[/color][gray](5)[/gray] [COLOR=steelblue][[/color] [green]1[/green], [green]2[/green], [green]5[/green], [green]4[/green], [green]7[/green] [COLOR=steelblue]][/color]

[silver]13:51:38.250[/silver] ⇨ [purple]arrstrval[/purple].[green]map[/green]([COLOR=steelblue]value[/color] => [purple]language_list[/purple][[COLOR=steelblue]value[/color]])
[silver]13:51:38.279[/silver] ⇦ ‣ [COLOR=steelblue]Array[/color][gray](5)[/gray] [COLOR=steelblue][[/color] [fuchsia]"Java"[/fuchsia], [fuchsia]"HTML"[/fuchsia], [fuchsia]"DOTNet"[/fuchsia], [fuchsia]"PHP"[/fuchsia], [fuchsia]"Oracle"[/fuchsia] [COLOR=steelblue]][/color]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top