My data is Look Like this
This is sub category list :
{
"statusCode": 200,
"status": "SUCCESS",
"responseContents": [
{
"webimage": [],
"appimage": [],
"_id": "6155c2c77f31f9b79ba4273b",
"Categories": "Tools & Machineries",
"Subcategories": [
"Power & Hand Tools ",
"Plant Cutting tools",
"All Tools & Home Improvement",
"Tool Storage & Organization",
"Tool Organisers",
"Pneumatic Tools",
"Carbide Cutting Tools",
"Tool Storage & Organization",
"Tools & Workshop Equipment",
"TOOLS & EQUIPMENTS",
"Hand Tools"
]
},
{
"webimage": [],
"appimage": [],
"_id": "6155c2c77f31f9b79ba4273c",
"Categories": "Furniture",
"Subcategories": [
"Wooden Furniture",
"Office Furniture",
"Kitchen Furniture",
"Modular Office Furniture",
"Industrial Furniture",
"Steel Furniture",
"Living Room Furniture",
"|Storage and Display Furniture",
"Entryway Furniture",
"Inflatable Furniture",
"Patio Furniture & Accessories",
"Storage and Display Furniture",
" Office & Commercial Furniture "
]
},
{
"webimage": [],
"appimage": [],
"_id": "6155c2c77f31f9b79ba4273d",
"Categories": "Safety & Security",
"Subcategories": [
"Industrial Safety Equipments",
"Safety Equipment",
"Fire Fighting Equipments",
"Traffic Safety Equipment",
"Marine Safety Equipment",
"Welding Safety Accessories",
"Work Safety Equipment & Gear",
"PERSONAL PROTECTION EQUIPMENTS",
"General Safety Equipment ",
" Fire Fighting & Prevention Products ",
"SAFETY MATERIALS (PPE)"
]
},
{
"webimage": [],
"appimage": [],
"_id": "6155c2c77f31f9b79ba4273e",
"Categories": "Lighting",
"Subcategories": [
"LED COMMERCIAL LIGHTING",
"Panel Light",
"Ceiling Lights",
"Indoor Lighting ",
"Flood Lights",
"Lighting Fixtures ",
"Lights & Fittings",
" Indoor Lights & Lighting Accessories"
]
}
...
]
}
Now I want to Fetch Data of a specific Category Only. For Example, I want to fetch Data OF Tools & Machineries Category Only. How can I do that please help
CodePudding user response:
const data = {"statusCode":200,"status":"SUCCESS","responseContents":[{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273b","Categories":"Tools & Machineries","Subcategories":["Power & Hand Tools ","Plant Cutting tools","All Tools & Home Improvement","Tool Storage & Organization","Tool Organisers","Pneumatic Tools","Carbide Cutting Tools","Tool Storage & Organization","Tools & Workshop Equipment","TOOLS & EQUIPMENTS","Hand Tools"]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273c","Categories":"Furniture","Subcategories":["Wooden Furniture","Office Furniture","Kitchen Furniture","Modular Office Furniture","Industrial Furniture","Steel Furniture","Living Room Furniture","|Storage and Display Furniture","Entryway Furniture","Inflatable Furniture","Patio Furniture & Accessories","Storage and Display Furniture"," Office & Commercial Furniture "]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273d","Categories":"Safety & Security","Subcategories":["Industrial Safety Equipments","Safety Equipment","Fire Fighting Equipments","Traffic Safety Equipment","Marine Safety Equipment","Welding Safety Accessories","Work Safety Equipment & Gear","PERSONAL PROTECTION EQUIPMENTS","General Safety Equipment "," Fire Fighting & Prevention Products ","SAFETY MATERIALS (PPE)"]},{"webimage":[],"appimage":[],"_id":"6155c2c77f31f9b79ba4273e","Categories":"Lighting","Subcategories":["LED COMMERCIAL LIGHTING","Panel Light","Ceiling Lights","Indoor Lighting ","Flood Lights","Lighting Fixtures ","Lights & Fittings"," Indoor Lights & Lighting Accessories"]}]};
function getBySubCategory(dataSet, category){
return dataSet.find(o => o.Categories===category);
}
const dataSet = data.responseContents;
console.log(getBySubCategory(dataSet, 'Tools & Machineries'));
console.log(getBySubCategory(dataSet, 'Safety & Security'));
.as-console-wrapper { max-height: 100% !important; top: 0 }