JSFiddle - React, Tailwind, and code Playground
by dshilkret
HTML
<span id="x">
dog
</span>
<span id="y" >
cat
</span>
JavaScript
var myObject2 =[{"result":{"number":"TASK0022700"}}];
var myObject = [
{
"query": {
"bool": {
"must": [
{
"term": {
"Field": "incident.x_150952_cosmos_se_u_url_3"
}
},
{
"term": {
"Field": "incident.time_worked"
}
}
]
}
}
}
];
//setTimeout(function(){
var x = $("#x").html();
console.log("x:" +x);
var y = $("#y").html();
console.log("y:" +y);
//},5000);
function findAndReplace(object, value, replacevalue){
for(var x in object){
if(typeof object[x] == typeof {}){
findAndReplace(object[x], value, replacevalue);
}
if(object[x] == value){
object["number"] = replacevalue;
// break; // uncomment to stop after first replacement
}
}
}
//findAndReplace(myObject, //"incident.x_150952_cosmos_se_u_url_3",x);
//findAndReplace(myObject, "incident.time_worked", y);
findAndReplace(myObject2, "TASK0022700", x);
document.body.innerHTML = JSON.stringify(myObject2);
console.log(myObject2);