JavaScript Why do we need self referential object in javascript

why do we need self referential object in javascript. example

let a = {};
a.self = a;

now a property self is referring to itself and become circular object.

in nodejs when we use routing library like hapi. the request object which we receive is circular

Answer:1

EDIT: I understood this question to ask "why are circular references allowed in JavaScript".

In general, I'd say an object having itself as a value of its property (a.self = a) is not very useful. If you have the reference to the object to take its property, you already have the reference to the object.

However, if the self-reference is deeper, then it makes a lot of sense. For example, trees that allow navigation up:

let tree = { children: [], parent: null };
tree.children.push({ children: [], parent: tree });

Here, tree.children[0].parent === tree. You have a circular object, but it serves a clear purpose: you can traverse the tree both downwards (via children) and upwards (via parent).

Answer:2

Using a Array.splice is fine as long as it's a single value. Suppose I have an array with 10 elements and I want to remove element 2,4 and 8, using Array.splice(index,1) in a for loop is a bad idea ...

Using a Array.splice is fine as long as it's a single value. Suppose I have an array with 10 elements and I want to remove element 2,4 and 8, using Array.splice(index,1) in a for loop is a bad idea ...

  1. remove multiple elements from list python
  2. remove multiple elements from array javascript
  3. remove multiple elements from set python
  4. remove multiple elements from list python by index
  5. remove multiple elements from vector c++
  6. remove multiple elements from array swift
  7. remove multiple elements from arraylist java
  8. remove multiple elements from an array
  9. remove multiple elements jquery
  10. remove multiple elements from dictionary python
  11. remove multiple elements from dom javascript
  12. remove multiple elements from array matlab
  13. remove multiple elements from list python using index
  14. remove multiple elements from list r
  15. remove multiple elements from numpy array python
  16. remove multiple elements from list java
  17. remove multiple elements from list c#
  18. remove multiple elements from array php
  19. remove multiple elements from string python
  20. remove multiple elements from array typescript

I have a simple AJAX GET request going to a certain PHP page: $.ajax({ type: "GET", url: "http://example.com/remote.php", success: function(response){ document.getElementById("...

I have a simple AJAX GET request going to a certain PHP page: $.ajax({ type: "GET", url: "http://example.com/remote.php", success: function(response){ document.getElementById("...

  1. from what page to start
  2. php from which page
  3. php check from which page
  4. contact form 7 from which page

const barStream = fs.createWriteStream('bar'); const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] }); throws an error: Incorrect value for stdio stream: WriteStream Doing this ...

const barStream = fs.createWriteStream('bar'); const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] }); throws an error: Incorrect value for stdio stream: WriteStream Doing this ...

I built a search page with WordPress & Algolia Search, and it's been working fine for a few months, but suddenly, I am getting the following error: Uncaught TypeError: Cannot read property '...

I built a search page with WordPress & Algolia Search, and it's been working fine for a few months, but suddenly, I am getting the following error: Uncaught TypeError: Cannot read property '...

  1. algolia wordpress search
  2. algolia search wordpress plugin