Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
so i am working with angular and i have a alert box with a text field that takes the input ({{name}}) and gives something like Welcome {{name}}. I want to match this {{name}} with my json array data which has name and a specific id.

What i want is the to match the {{name}} with json array name and get the corresponding id of that name. And also get only the last 4 digits of that id.

So the expected output should be something like
i/p: name="tom"
o/p: 7647

Any help would be appreciated thanks a lot.

What I have tried:

<pre>
JSON data:

var json=[{
name="bob",
id="FYW1985274"
},{
name="tom",
id="FYW1687647"
}]
JS

function xyz{
 var loginName = document.getElementById("login").value

  var search = json.map(d => d.name)

if(search.includes(loginName)){
  json[i].id // i should be index of matching name // I do not know how to get corresponding id with last 4 digits for that name.
} 
HTML
<welcome id="login" name="{{name}}"></welcome>
When i am trying to get name with id="login" it's giving me entire "Welcome name" but i want only name.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900