Advertisement
bilelh

Json search

Dec 15th, 2021
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8">
  5.   <meta name="viewport" content="width=device-width">
  6.   <title>JS Bin</title>
  7. </head>
  8. <body>
  9.   <div id="res"></div>
  10. <script>
  11.   var data=[{"nom":"Nom Pr\u00e9nom","mobile":"","Email":""},{"nom":"QQun d\'autre","mobile":"02020202","Email":""},{"nom":"Toto","mobile":"080282920","Email":"bil@test.me"}]
  12. function getContact(mobile) {
  13.   return data.filter(
  14.       function(data){ return data.mobile == mobile }
  15.   );
  16. }
  17.  
  18. var contact = getContact('080282920');
  19.   document.getElementById('res').innerHTML=contact[0].nom;
  20.   </script>
  21. </body>
  22. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement