Soy un poco nuevo con javascript. ¿Hay alguna manera de encontrar todos los icon y obtener su valor y luego reemplazar sus valores por uno nuevo?
Necesito reemplazar todo fa/FaCopy con fcb/FcbCopy en la carga útil json a continuación. ¿Alguna biblioteca o función que puedas compartir?
[ { "section": "feature-list", "data": { "title": "Title here", "body": "body here", "features": [ { "title": "Title here 1", "image": "body here", "icon": "fa/FaCopy" }, { "title": "Title here 2", "image": "body here", "icon": "fa/FaCopy" }, { "title": "Title here 3", "image": "body here", "icon": "fa/FaCopy" } ] } }, { "section": "title-list", "data": { "title": "Title here", "titles": { "list": [ { "title": "Title here 1", "icon": "fa/FaCopy" }, { "title": "Title here 2", "icon": "fa/FaCopy" }, { "title": "Title here 3", "icon": "fa/FaCopy" } ] } } } ]Esta será una solución muy personalizada y dependerá profundamente de sus datos. Si su tipo de datos no cambia y permanece igual, entonces podría usar/modificar algo como esto.
// DATA = Your array const result = DATA.map((list) => ({ ...list, data: { ...list.data, features: list.data.features?.map((feature) => ({ ...feature, icon: feature.icon === 'fa/FaCopy' ? 'fcb/FcbCopy' : feature.icon })), }, })); console.log(result); // your expected result