All Questions
Tagged with object ecmascript-6
1,090
questions
0
votes
0
answers
26
views
How do get search filter data in es6
// Filter rows based on string values and exclude from whiteList
const whiteList = rows.map(sel => sel.RuleAutoID); // Array of IDs to exclude
console.log('whiteList', whiteList);
// Assuming you'...
0
votes
2
answers
80
views
How to filter an array that has mixed data types
I have an array which is like this:
const AllFiles = [
{name: "ExistingFile1", mimetype: "image/jpg", size: "500"},
[
File, // This is the New File itself ...
-1
votes
2
answers
103
views
Sorting/Manipulating an array of objects
I need help in writing a function to sort an array of objects
all objects with xid are bottom in array
object (assume A) which has options array might contain xid in step object, This xid is also ...
1
vote
1
answer
93
views
Definition of `integer index` in JavaScript (ECMAScript 2015)
I'm trying to understand how a JavaSript object sorts its properties. As far as I understood, from ECMA262, the first properties are always an integer index properties. For example, if print these ...
1
vote
1
answer
41
views
sum the value inside array of objects based on multiple conditions
I have this object
[
{
"year": 2020,
"term": 1,
"worthAmountEGP": 0
},
{
"year": 2020,
...
0
votes
1
answer
19
views
Make object key as value and assign new key to value in array of objects
I have an array of objects with multiple properties. I want to be able to make the property's key a value and assign a new key to my value.
My code:
var list = [
{
you: 100,
me: 75,
...
2
votes
0
answers
93
views
Javascript Object() vs new Object() for ES6
I've seen a number of questions about new Object vs new Object() or new Object() vs {}, but I'm wondering about what the difference is between Object() and new Object()? In other words, what's the ...
0
votes
0
answers
25
views
Array not returning pushed values from Function [duplicate]
I declare an array outside of a function and push values inside the function. How do I get that array populated outside the function?
My code:
const higher_fnc = (query_name) => {
return axios({
...
0
votes
0
answers
16
views
Object not getting populated by Axios Function [duplicate]
I have an axios function using GraphQL. It is a nested axios that is supposed to populate an object but is not. What is missing in my code?
My code:
const higher_fnc = (query_name) => {
return ...
-1
votes
4
answers
64
views
Add values from Array to every Object in Array
For a project i need to push the values of an array into every object in another array.
What i have so far:
closed_status = [{
"project_no": 5,
"priority": 3,
"s_status": "S8",
"...
0
votes
1
answer
36
views
Neater way to assign to variable from Object
Is there a neater way to assign the values to objects rather than what I have:
My code:
let val1 = result.data.data.table.val1;
let val2 = result.data.data.table.test.val2;
let val3 = result.data.data....
2
votes
3
answers
59
views
Neater way to create an object
I am creating an object with values from an api response. Is there a neater way to do this?
My code:
const variables = {
name: result.data.data.table.name,
org: the_org,
val1: result.data....
0
votes
0
answers
213
views
Error when passing array of objects as variable in graphQL
I am trying to pass an array of objects as a variable in a graphQL mutation. The variables are populated from a forEach loop and pass the mutation to an axios function.
My code:
const query = "...
-1
votes
1
answer
24
views
Add to object with every iteration without replacing
I have an object outside of the function that I want to populate with every iteration and call that object after the iteration is done but I am only able to see the last element in my object. How do I ...
0
votes
2
answers
62
views
Transform the array of object or nestobject into desire format
I am trying to transform the array object into new object with some new key name and rest of the key convert into cameCase
Example:
1. Old Key to New Key name
old key: orgId converting into ...
-3
votes
1
answer
964
views
How to iterate over Json object in javascript or Ecmascript? [duplicate]
I have this json Response and having difficulty in iterating over this json structure.The idea is to print the numbers written within the square brackets if they match with "Data" Json which ...
-2
votes
2
answers
71
views
Find matching object property in array and merge into new object [closed]
I have an array of objects, where I want to find the objects having same value for name property and then merge them into single object by adding their values & subvalues.
const arr = [
{ id: 1, ...
0
votes
0
answers
150
views
Create array of objects from graphql response
I have a response from graphql that I want to reformat and assign to a variable so that I can keep using them across my app.
GraphQL response:
{
"data": {
"organization"...
-2
votes
1
answer
271
views
JavaScript get comma separated values based condition
Hi I'm having an issue filtering out the values from array of objects. So basically I've an array of object
const arr = [
{
"id": null,
"name": null,
&...
0
votes
1
answer
68
views
Javascript - convert array multi level to single level [duplicate]
I am trying to map a complex object array document to a single level array. For example
const data = [
{
"id": 1,
"name": "Beauty",
"...
0
votes
1
answer
87
views
Passing a string as a property to use the map function
I have something like this
{
"title": "JSON",
"content": [
{
"item": "23",
"url":"ug.coml"
...
0
votes
3
answers
287
views
Is there any way to create object using function in TypeScript , like JavaScript?
I want to create Object using Function in TypeScript like JavaScript.
Eg.
function Box(a,b) {
this.width=a;
this.height=b;
}
var box=new Box(3,5);
I tried this code in TypeScript, It throws ...
3
votes
2
answers
2k
views
Add a new key and value to a Javascript object from an existing array of values
I have an existing array of ids that I'm trying to iterate over to add each as an id: key to an existing array of objects. I have tried a number of different loops (for, for in, map, forEach), but I ...
-2
votes
2
answers
83
views
Merge objects of single array on basis of object key [closed]
I'm confused to merge array contents from JavaScript.
Please help to get the best way to get desired result. A i also have tried other ways referred on SO.
[
{
"Afghanistan": ...
1
vote
2
answers
52
views
Converting object to array with objects
I need help sorting this out, I tried object.keys with map, but can't get too far, so, I have this object and each key has an array:
const first = {
"apples": [
"5.78",
...
0
votes
3
answers
907
views
Map through a Javascript array of objects and return a new one satisfying a condition
Having the following data structure:
[
{
"items": [
{
"name": "View Profile",
"href": "/profile&...
0
votes
2
answers
47
views
How to take only specific indexes and map to another indexes?
I need to make an api call with particular parameter.
See example below:
const apiFunc = (someId, anotherId) => apiCall(someId, anotherId) }
However in an array called someArr I get something like [...
-2
votes
1
answer
57
views
How do I do "Reverse destructuring"
We all know about destructuring objects in ES6+
const myObject = {name: 'John', age: 30, eyeColor: 'brown'}
const {name, age, eyeColor} = myObject
... is there a "cleaner" way to do the ...
0
votes
1
answer
65
views
Spreading array to set a new state
I am working in React.JS and trying to set a new state by spreading array of objects and changing a value of one of them. I have an array of objects with key and another object as a value. Like this:
...
0
votes
5
answers
161
views
Flatten then map object to array
I have an object that needs to be mapped into array with the key as a property. The object looks like:
{
Cat: {
value: 50
},
Dog: {
value: 80
}
}
I need to convert this to:
[
{
animal:...
0
votes
1
answer
29
views
Creating and populating elements for each object in array, with respective object data
I am trying to create a list of values from a sorted array that will automatically generate a DOM element for each unique object inside of the sorted array.
I have a JSFiddle here since it requires ...
0
votes
0
answers
110
views
How to get window object output in console using 'this' keyword in standalone function call
I want to check how 'this' keyword is behaving in Javascript ES6. To perform this I wrote code snippets to check output of 'this' keyword in object and also normal standalone function.
When I call the ...
-5
votes
2
answers
127
views
Group all the values of common keys as an array in array of objects [duplicate]
I have an array of objects as
const arr = [
{
"id": 2,
"key": "cc_edit"
},
{
"id": 4,
...
0
votes
1
answer
321
views
Apply child value to parent key if specific key exists in child in object
const obj = {
uid: "893212",
a: {name: "Down here!", uid: "1231"},
b: {
c: {uid: "5965"},
name: "bud name",
},
d: {name: "...
1
vote
2
answers
107
views
JS/lodash - Can we efficiently change an 'array of Object' having value 'Array of Object' into array of Object with single array values
I have used lodash to create chunks of arrays (batches).
let values = {
'key1' : [lotsOfValues1],
'key2' : [lotsOfValues2]
};
let keys = ['key1', 'key2'];
let arrObj = [];
keys.forEach((key) =&...
2
votes
4
answers
153
views
Is there a ES6 shortcut way to compare array of elements and object key and remove the non-matching elements?
I am trying to find a shortcut or single line of code that can active following:
I have a array selectedFields consisting of elements:
selectedFields = [ "time", "age", "city&...
0
votes
1
answer
122
views
Invalid left-hand side in assignment expression for deep nested object in react
I have a reactjs project in which there is a useState variable which is very nested. Something like this:
{
chart: {
type: 'bar',
height: 430
},
plotOptions: {
bar: {
...
0
votes
3
answers
90
views
Remove some array object comparing with another array JavaScript
I have two dynamic array. One is Array of objects and another one is array of some string.
First Array is :
const initialColumns = [
{content: "Registered Name", id: "name"},
{ ...
0
votes
0
answers
14
views
Why am I allowed to use variable as property name in javascript object creation without using ES6 bracket notation? [duplicate]
Consider the following example
var x = 1;
var obj = {y:1, x};
console.log(obj, obj.x);
I have tried to find many stackoverflow posts and MDN documentations, but I fail to find any reference ...
0
votes
1
answer
127
views
Assigning values to arrays with dynamic keys in nested objects in javascript
I have problems understanding and creating dynamic keys of an object and assigning values to nested objects.
desired output:
{
SULS: {
"Main Site": ["Home Page", "Login Page&...
1
vote
4
answers
267
views
turn a flat array into cell like objects for a grid
I have an array that looks like similar to this,
[
['column1', 'column2', 'column3', 'column4', 'column5'],
['2column1', '2column2', '2column3', '2column4', '2column5']
]
I wanting to turn ...
0
votes
1
answer
39
views
How to Combine Same key JavaScript Object to one Array Dynamically
How to Combine Same key JavaScript Object to one Array Dynamically in JavaScript/Nodejs and Produce given Input to expected output,
Please do help me on this. that would be really helpful.
Example -
[
...
0
votes
2
answers
471
views
How to get object value if key is not string but you are given string key to find value
How to get value of Object if its key is not string but you are given a string to find value
Example: let obj={ arr: ["Kapil"]};
find value of obj.arr is you are given '...
0
votes
0
answers
17
views
How to create a copy of array without modifying it old value? [duplicate]
I have two arrays tasks and updatedTasks. When the first api call is made, one of the properties is updated. When I make a copy of tasks array and make a second API to update other property, it adds ...
-6
votes
1
answer
60
views
Is there a way to convert an array of arrays to JSON? [closed]
let letter = ["a", "b", "c"];
let number = [1, 2, 3];
let arrays = [letter, number]
// What code will achieve the following result?
let result = [
{
letter: &...
0
votes
2
answers
51
views
js common function which calculates and assign to object values?
Example of what i'm trying to achieve
I want to make an object in react which will calculate one its key value from other keys using this function and the 'this' keyword so that I can use this ...
0
votes
3
answers
41
views
How to filer an array of objects and return only one object based on a specific value
I have an array containing two plan objects:
[ { "id": "price_aehdw424i7rxyeqiquedwuy",
"name": "Monthly Plan",
"price": 2900,
"...
-1
votes
1
answer
207
views
How to replace the object array using simple filter and spread operators
I need a suggestion for the below code. The objective here is to remove the specific array if the mentioned menuKey is present.
Note: sdb.menu = 'account-links' (Declared in another file);
const { ...
0
votes
2
answers
359
views
Filter nested array in object based on specific values of another array [duplicate]
I have an array of Objects, and every object has an array of strings (tags), I need to filter the array of objects based on another array.
data: [
{
"id":"Nerium",
...
-1
votes
1
answer
36
views
How can we check key avaibality in objects? [duplicate]
const student= [
{
student_id: 0,
name: "Rhoda Salas",
checked:"checked"
},
{
student_id: 1,
name: "Jewell Avery"
},
{
...