Questions tagged [object-properties]

117 questions
27
votes
7 answers

Accessing different properties in a typescript union type

I'm creating a function that handles objects from the database. I have two different data structures where the same property has a different name. I can't change that, so I have to handle it in JavaScript. The objects have other differences, but…
KWeiss
  • 2,954
  • 3
  • 21
  • 37
27
votes
5 answers

Javascript - catch access to property of object

Is it possible to capture when a (any) property of an object is accessed, or attempting to be accessed? Example: I have created custom object Foo var Foo = (function(){ var self = {}; //... set a few properties return self; })(); Then…
Randy Hall
  • 7,716
  • 16
  • 73
  • 151
15
votes
1 answer

JavaScript - Proxy set vs. defineProperty

I want to build a proxy that detects changes to an object: New properties are defined. Existing properties are changed. Code Sample 1 - defineProperty const me = { name: "Matt" } const proxy = new Proxy(me, { defineProperty: function(target,…
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
12
votes
4 answers

Object properties dynamic delete

I am curious about an improved way to dynamically delete properties from a javascript object based on wildcards. Firstly, suppose I have the following object: object = { checkbox_description_1 : 'Chatoyant', checkbox_description_2 :…
Symbal
  • 360
  • 1
  • 3
  • 12
11
votes
2 answers

Why is this object property undefined?

Consider the code below. The first console.log correctly logs the image, and you can see its properties in the image below. However, when I try logging one if its properties to the console, I get undefined! console.log(that.data[0].cards); //works…
maxedison
  • 17,243
  • 14
  • 67
  • 114
8
votes
3 answers

Override Object Property for unit testing purposes

I am using Jest to perform unit tests on a Node.js app, where the code source is written in TypeScript and then compiled into JavaScript. In one of the classes that I wish to test, an external module is imported and a method from this module is…
Reyedy
  • 918
  • 2
  • 13
  • 36
8
votes
3 answers

Default sort property

Using PowerShell, I'm trying to understand the concept of default sort property. According to this example, provided for the Sort-Object command : PS C:\>get-childitem | sort-object Because no properties are specified, Sort-Object uses the default…
Jérôme
  • 26,567
  • 29
  • 98
  • 120
6
votes
1 answer

How can I make object properties in console.log(obj) display alphabetically in Chrome?

It used to be that, when I used console.log(obj) to display an object's properties in Javascript, the properties would display alphabetically. Recently, this seems to have changed. I assume that the new order is closer to how the properties are…
IndigoFenix
  • 291
  • 2
  • 20
6
votes
2 answers

Get the difference two objects by subtracting properties

I am trying to get the difference between two objects previousChart: {BWP: 1, ZAR: 1.3, USD: 0.09324, number: 1}, currentChart: {BWP: 1, ZAR: 1.35, USD: 0.01, number: 2} The desired answer is: newObject ={BWP: 0, ZAR: 0.05, USD: 0.08324, number:…
5
votes
3 answers

Rxjs - remap object with observables as values

I got an observable like this: const original = Observable.of({ a: this.http.get('https://jsonplaceholder.typicode.com/todos/11'), b: this.http.get('https://jsonplaceholder.typicode.com/todos/22'), c:…
5
votes
4 answers

Is an if with a continue a good pattern to prevent excessive nesting while iterating over properties in Javascript?

I normally use this pattern to iterate over object properties: for(var property in object) { if(object.hasOwnProperty(property)) { ... } } I don't like this excessive indentation and recently it was pointed out to me that I could get…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
4
votes
0 answers

How can I query Object Properties in an OWL ontology

I am working with the FoodOn ontology and need to figure out if a certain class is somehow related to another class. Typical use case: Can a vegan person eat honey? No, because honey is a subsub class of "invertebrate animal food product"! I am…
Solarer
  • 71
  • 1
4
votes
2 answers

How to iterate through all properties and its values in Typescript class

How do I iterate through list of class properties and get the values of each (only the properties and not the functions) class Person{ name:string; age:number; address:Address; getObjectProperties(){ let json = {}; // I need to…
Dharshni
  • 181
  • 1
  • 6
4
votes
3 answers

Access static object property through variable name

I know its possible to access an object property/method using a variable as its name ex.: $propName = 'something'; $something = $object->$propName; Is it possible to do the same w/ constants or static properties? I've tried: $constName =…
CarlosCarucce
  • 3,420
  • 1
  • 28
  • 51
4
votes
4 answers

Passing Objects into PHP constructor error

Is it possible to pass an object into the constructor of a PHP class, and set that object as a global variable that can be used by the rest of the functions in the class? For example: class test { function __construct($arg1, $arg2, $arg3) { …
littleK
  • 19,521
  • 30
  • 128
  • 188
1
2 3 4 5 6 7 8