How to add custom property of object using .map

teres

I'm using the plugin Bootstrap Select Picker, which allow (as the same of the normal select control) to select multiple values.

If I call: $('#items).val() I'll an array of the values selected in the select control:

["1", "2"]

I would like to include each value in another object like:

var main = {
   items: $('#items').val()
}

how can show also a structure like this:

[ { id: 1 }, {id: 2} ]
Maheer Ali

use map method and change it into object

let arr = ["1","2"];
    arr = arr.map(num => ({id:parseInt(num)}));
console.log(arr);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add an object as a property of a JsonObject object?

How do you add more property values to a custom object

How to add an object to a generic list property of an instance of a class using reflection

How to add a custom prefix in a << operator for a custom object

How to add a custom property to ILogger

WEB API - how to add value to custom property in User using identity

Custom property delegation for arrays using a map

How do I add a property on a property of an object?

Map a property to list of object using AutoMapper CreateMap

How to add custom property in Quasar?

Instantiate an object with a property of custom type using dictionary

React Native How do I add an object in an array using the map?

Powershell - how do I add multiple objects to a property on a custom object?

How to add an object property inside an array using a variable name for javascript?

How to add a custom field to an existing object in salesforce using Java

How to add custom map and custom data to Highmaps?

How to add a Property Name and Value to a JavaScript Object using a function?

Map object types using custom converter

How to preserve object property casing when using Rxjs map function

How to add property to an object?

How to map entity property with custom query and Hibernate

How to add property to an object from an API using react hooks useState

How to using ObjectMapper to map value of an json property to Object when my object have an contractor set this property is null

How to add a property to my object using a map

How do I use map function, so I can add the index as a property to the newly constructed object?

How to add a style to an object property

TypeScript: Add custom type to a single property in object

How to add elements in an object while traversing through an array using map?

how to add custom property and method to google map with TypeScript