Questions tagged [javascript-objects]

Use this tag for questions related to JavaScript objects.

In general an object is any entity that can be manipulated by commands in a programming language. An object can be a value, a variable, a function, or a complex data-structure. In object-oriented programming, an object refers to an instance of a class.

In JavaScript, almost "everything" is an object.

  • Booleans can be objects (or primitive data treated as objects)
  • Numbers can be objects (or primitive data treated as objects)
  • Strings can be objects (or primitive data treated as objects)
  • Dates are always objects
  • Maths are always objects
  • Regular expressions are always objects
  • Arrays are always objects
  • Functions are always objects
  • Objects are objects

This tag is specific to language so JavaScript-objects.

See also:

  • (Used as template for creating new objects)
  • (Object-oriented programming)

Attribution: https://stackoverflow.com/tags/object/info

Links

7142 questions
1
vote
4 answers

return an object with similar structured but filtered

I have the following object: const myObject = { "-Lz8YxHiwp8QZW3TqAFn": Object { "first": "Breanna", "last": "Blah", }, "-Lz8YxHqQXWoaGOFRLrO": Object { "first": "Joshua", "last": "Blah", }, "-Lz8YxHsMItaaTVNyQRE": Object { "first":…
FabricioG
  • 3,107
  • 6
  • 35
  • 74
1
vote
0 answers

Replacing switch statement with Object literal with booleans

I have this switch statement where a, b, c and d can be true or false, but only one of them is going to be true, and when one of them is true it returns X which is a variable. How can I replace this switch statement with an object literal? switch…
1
vote
1 answer

Javascript Tic Tac Toe Game does not display Tie whenever win combos are not chosen

I am creating a Tic Tac Toe game using javascript's immediately invoked function element(IIFE). So far, I have managed to create the game board with CSS and HTML and have also managed to get game play that identifies the winner based on the sign. I…
Reemy876
  • 13
  • 5
1
vote
2 answers

How to create a Javascript object from an array of known keys, but with the values initialized to null?

I have a JS object from which I will extract an array of keys (using Object.keys()) and then I want to use those same keys to create a different object, but this time with its values initialized to null. In Python, I would do something…
LeperAffinity666
  • 364
  • 4
  • 14
1
vote
1 answer

Comparing original form data to edited data

I have a form that is built in with React with react-hook-form that allows users to add dynamic steps using the useFieldArray method which comes with react-hook-form. My problem is that how can I compare the original data that was passed into the…
1
vote
3 answers

Java Script fetches Document objects in infinite loop

I am writing a code to add a div depending on a set of 'object' found in document on click of button. When Document.getElementsByTagName('object'); there is only one object, but it goes in to an infinite loop! giving me incremented value of…
Anna
  • 23
  • 4
1
vote
3 answers

Compare two arrays of objects, and remove if object value is equal

I've tried modifying some of the similar solutions on here but I keep getting stuck, I believe I have part of this figured out however, the main caveat is that: Some of the objects have extra keys, which renders my object comparison logic useless. I…
elguapo
  • 155
  • 1
  • 14
1
vote
4 answers

How to break a single JSON object in multiple objects

I am new to this please excuse me if I make any mistake. I am reading a single row of data from database , the data which I receive is JSON object and looks like this: var details = {jan: '2591.00', feb: '4898.00', mar: '26290.00', apr: '22719.00',…
ada
  • 11
  • 1
1
vote
1 answer

How to acces to parent object in event listener?

I need to access the parent object (not window) into an event listener. Actually I get window with self, and the WebSocket object (event listener target) with this. I want to get the ScratchCloud object (parent). Here is the JS code: var…
Virinas-code
  • 180
  • 3
  • 14
1
vote
1 answer

JavaScript are this references in the body of callback functions resolved prior to method invocation when using arrow functions as callback functions?

Trying to figure out how this references resolve to the lexical context when using arrow functions as callback functions. My suspicion is the this references in the body of the callback function are resolved before the method is invoked. I.e.,…
Andy
  • 7
  • 3
1
vote
1 answer

How to turn an array of arrays with varying length into a nested object tree in javascript

I need to process files that are structured like Title /foo/bar/foo/bar 1 /foo/bar/bar 2 /bar/foo 3 /bar/foo/bar 4 It's easy enough to parse this into an array of arrays, by splitting at every / and \n. However, once I get an array of arrays, I…
1
vote
3 answers

Change the nested objects’ keys recursively

I have object like this which contains many keys named label and choices: const obj = { "label": "mylabel", "choices": [ { "label": "mylabel_11", "choices": { "label": "mylabel_12", "choices": [ /* … */ ] } …
whitebear
  • 11,200
  • 24
  • 114
  • 237
1
vote
1 answer

Why can't I single-line object properties from objects returned from async functions?

I am wanting to use an object that is returned from an asynchronous function. async function myPromise() { console.log("Single-line", await getUsers().quote); let users = await getUsers(); console.log("Multi-line", users.quote); } async…
Liam Pillay
  • 592
  • 1
  • 4
  • 19
1
vote
2 answers

How to delete Object if value of nested object property value < epoch

I have an object tree that contains the following values. data = { TD2n9thHQgyvWdPhOkHQ: { heartbeat: 1644637961658, joinTime: 1644636756368, }, IASJDAIODJiklk243oi: { heartbeat: 1644637961658, joinTime: 1644637961658, } …
s3SIM
  • 11
  • 1
1
vote
1 answer

I want to add many object inside a nested array of object with a specific key in javascript

I want to add one or many objects inside an array of object which a specific key whose structure has been shown below. Help would be appreciated structure: { "nameEn": "string", "nameFr": "string", "descriptionFr": "string", "descriptionEn":…
Justin Abodo
  • 35
  • 1
  • 6
1 2 3
99
100