• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

87
Views
Find by key and replace the value in an object

I'm a bit new with javascript. Is there a way to find all icon and get their value and then replace their values with a new one?

I need to replace all of fa/FaCopy with fcb/FcbCopy in the json payload below. Any libraries or functions you can share?

[
  {
    "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"
          }
        ]
      }
    }
  }
]

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This will be very customized solution and deeply depended on your data. If your data type will not change and remain same then you could use/modify something like this.

// 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
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error