I need to create a new JSON object called selectedProductAttributes, which is generated by comparing the contents of a second JSON object (selectedProductAttributesNames) with a third object (allProductAttributes). Let me provide some examples to make this clearer.
The first example, called allProductAttributes, is a JSON object containing various attributes for form fields:
$scope.allProductAttributes = [
{
name: 'postcode',
title: 'Postcode',
required: true,
type: 'text',
max: '10',
placeholder: 'Enter a postcode'
},
{
name: 'Term',
title: 'Contract term',
required: true,
type: 'number',
},
{
name: 'bandwidth',
title: 'bandwidth',
type: 'select',
options: [
{id: 10, name: '10 mb/s'},
{id: 100, name: '100 mb/s'},
{id: 1000, name: '1000 mb/s'},
{id: 10000, name: '10000 mb/s'}
]
},
{
name: 'service',
title: 'Service',
required: true,
}
]
The next JSON object, selectedProductAttributesNames, contains a list of the form fields that the user wants to select from allProductAttributes:
$scope.selectedProductAttributesNames = [
"postcode",
"service"
]
So when the user selects 'postcode' and 'service' in selectedProductAttributesNames, a new JSON object should be created with the corresponding form field attributes from allProductAttributes:
$scope.selectedProductAttributes = [
{
name: 'postcode',
title: 'Postcode',
required: true,
type: 'text',
max: '10',
placeholder: 'Enter a postcode'
},
{
name: 'service',
title: 'Service',
required: true,
}
]
If this explanation is unclear, please let me know. Can anyone suggest how I can achieve this? Thank you!