Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "N": "3M",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
- },
- {
- "N": "ABC corp",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>",
- "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
- }
- ]
- [
- {
- "N": "3M",
- "a": "red",
- "c": "red",
- "r": "red",
- "p": "gray"
- },
- {
- "N": "ABC corp",
- "a": "red",
- "c": "red",
- "r": "green",
- "p": "gray"
- }
- ]
- var data = [{
- "N": "3M",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
- }, {
- "N": "ABC corp",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>",
- "p": "<img src="https://a.na7.visual.force.com/resource/1260007793000/a/iconset/gray.gif" alt=" " height="16" width="1" border="0"/>"
- }];
- var modified = data.reduce(function (outArr, entry) {
- var outObj = {};
- for (key in entry) {
- if (entry.hasOwnProperty(key)) {
- var item = entry[key];
- var node = document.createElement("div");
- node.innerHTML = item;
- var img = node.querySelector("img");
- outObj[key] = img ? img.alt : item;
- }
- }
- outArr.push(outObj);
- return outArr;
- }, []); //[{"N":"3M","a":"red","c":"red","r":"red","p":" "},{"N":"ABC corp","a":"red","c":"red","r":"green","p":" "}]
- var obj=[
- {
- "N": "3M",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>"
- },
- {
- "N": "ABC corp",
- "a": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "c": "<img src="/img/samples/flag_red.gif" alt="red" height="16" width="16" border="0"/>",
- "r": "<img src="/img/samples/flag_green.gif" alt="green" height="16" width="16" border="0"/>"
- }
- ];
- for(var k in obj){
- for (name in obj[k]) {
- if(obj[k][name].indexOf("<img") != -1) {
- // I have made logic based on "flag_", this can be change as per your requirement.
- var src= obj[k][name].substring(obj[k][name].indexOf("flag_")+5,obj[k][name].indexOf(".gif"));
- obj[k][name]=src;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement