JavaScript Iterate in array extract and add to new list if object value is true in javascript

I have an array like below and I want to extract objects and sub-array and create a new array if the selected object value is true

menu: [
  {
    category_name: "snacks",
    selected: true
    items: [
      {
        item_name: "burger",
        price: 00,
        bestseller: false
      }
    ]
  },
  {
    category_name: "tiffins",
    selected: false
    items: [
      {
        item_name: "idly",
        price: 00,
        bestseller: false
      }
    ]
  },
]

i want new array would be like this

new_menu: [
  {
    category_name: "snacks",
    items: [
      {
        item_name: "burger",
        price: 00,
        bestseller: false
      }
    ]
  },
]
Answer:1

You can try this:

const new_menu = menu
  // Get the selected items
 .filter(m => m.sellected)
  // Get rid of the `sellected` property
 .map(({ sellected, ...m }) => m)
Answer:2

I have included javascript for dynamically adding input fields but the first time its clicked it doesn't style correctly. Here is how it looks before utilizing add button (ignore the Author 1/...

I have included javascript for dynamically adding input fields but the first time its clicked it doesn't style correctly. Here is how it looks before utilizing add button (ignore the Author 1/...

  1. dynamic adding new input field
  2. dynamic adding new input field ionic

I have been struggling to include a profile picture upload along with regular text data and send that all to the back end to create a new user through mongoose. I have tried everything from ng-file-...

I have been struggling to include a profile picture upload along with regular text data and send that all to the back end to create a new user through mongoose. I have tried everything from ng-file-...

  1. angular image upload with preview
  2. angular image upload component
  3. angular image upload npm
  4. angular image upload example
  5. angular image upload stackblitz
  6. angular image upload with crop
  7. angular image upload base64
  8. angular image upload library
  9. angular image upload validation
  10. angular image upload plugin
  11. angular image upload made easy
  12. angular image upload with spring boot
  13. angular image upload with preview example
  14. angular image upload firebase
  15. angular image upload .net core
  16. angular image upload and display
  17. angular image upload and retrieve with firebase storage
  18. angular image upload formdata
  19. angular image upload drag and drop
  20. angular image upload with form data

In my code, the x value is undefined. If I remove if block, the x value is displayed as 77. I don't understand why if block is modifying the x value. var x = 77; function fn() { if (false) {...

In my code, the x value is undefined. If I remove if block, the x value is displayed as 77. I don't understand why if block is modifying the x value. var x = 77; function fn() { if (false) {...

  1. javascript hoisting functions
  2. javascript hoisting why
  3. javascript hoisting let
  4. javascript hoisting quiz
  5. javascript hoisting const
  6. javascript hoisting es6
  7. javascript hoisting stack overflow
  8. javascript hoisting questions
  9. javascript hoisting interview questions
  10. javascript hoisting medium
  11. javascript hoisting mdn
  12. javascript hoisting tutorial
  13. javascript hoisting variables
  14. javascript hoisting definition
  15. javascript hoisting meaning
  16. javascript hoisting not working
  17. javascript hoisting advantages
  18. javascript hoisting order
  19. javascript hoisting problem
  20. javascript hoisting inside function

I have a JavaScript validation on form, every time the form is submitted it will empty the boxes. I need to change it, when the form is filled up incomplete with empty boxes. it will not clear all the ...

I have a JavaScript validation on form, every time the form is submitted it will empty the boxes. I need to change it, when the form is filled up incomplete with empty boxes. it will not clear all the ...

  1. styling input validation
  2. custom field validation message