I have this array of objects
[
{
"id": "41796005",
"name": " Manoj ",
"phoneno": " xyz",
"email": "xyz@gmail.com"
},
{
"id": "160865953",
"name": " Manisha Sajnani ",
"phoneno": "xyz",
"email": "xyz@gmail.com"
}
]
This is the id div’s in the html page
<div class="tuple on" data-tuple-id="160865953" ></div>
so my question is that how can i append the id's div phoneno value if both matches
the div’s are in the no. of 40
sho how can we loop upon them & append that data to the id which is available in the array
>Solution :
Loop on data and div, compare id and append your data as html on div.
Example:
var data = [{
"id": "41796005",
"name": " Manoj ",
"phoneno": " xyz",
"email": "xyz@gmail.com"
},
{
"id": "160865953",
"name": " Manisha Sajnani ",
"phoneno": "xyz",
"email": "xyz@gmail.com"
}
]
$('.tuple').each(function() {
var divid = $(this).data("tuple-id");
var _id = $(this);
$.each(data, function(key, val) {
if (divid == val.id) {
_id.html(val.name + '---' + val.phoneno + '---'+ val.email)
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tuple on" data-tuple-id="160865953"></div>