JavaScript What are prototypes and why are they added to my json object

I am making an ajax call using jquery to a PHP script that sends back a json encoded string as an object.

{
   "errors":{
      "name":"Name is empty",
      "gender":"Gender is empty"
   },
   "success":false,
   "message":"FAIL"
}

This is the json returned and since I'm using dataType: 'json' within my ajax call it is converted to an object which I have then console logged to observe.

I see that key/value pairs are in there but also something (prototypes) that wasn't a part of the json string. What is it and where did come from? Are these functions I could use?

I am attaching a screenshot as typing it would mess it up.

enter image description here

Answer:1

Don't worry, you can ignore it.

JavaScript uses prototypical inheritance: An object inherits features from another object, called its prototype (which may, in turn, have its own prototype, and so on). It's possible to create an object that doesn't have a prototype, but by default, all objects do.

Plain objects in JavaScript inherit from the basic object prototype (which you can access via the Object.prototype property): When your JSON is parsed and the plain objects for its contents are created, their prototype is that object, which provides the toString, valueOf, and hasOwnProperty, and other methods and (on browsers) the __proto__ property (though you should pretend that last one isn't there):

const json = "{}";
const obj = JSON.parse(json);
console.log(Object.getPrototypeOf(obj) === Object.prototype); // true
Answer:2

In Nuxt.js, I did this folder structure: ├── parent │   ├── child1.vue │   └── child2.vue ├── parent.vue In parent.vue, I have this: <template> <div> <h3>Parent ...

In Nuxt.js, I did this folder structure: ├── parent │   ├── child1.vue │   └── child2.vue ├── parent.vue In parent.vue, I have this: <template> <div> <h3>Parent ...

I have created script for storing some data. Function demo returns data in JSON format. But I want to create a JSON file for my external project. var demo = function(table) { // JSON file var ...

I have created script for storing some data. Function demo returns data in JSON format. But I want to create a JSON file for my external project. var demo = function(table) { // JSON file var ...

  1. export variable from bash script
  2. export variable from function javascript
  3. export variable from js file
  4. export variable from file
  5. export variable from shell script
  6. export variable from script
  7. export variable from matlab to excel
  8. export variable from subshell to parent shell
  9. export variable from makefile
  10. export variable from python
  11. export variable from shell script to environment
  12. export variable from react component
  13. export variable from python to bash
  14. export variable from function python
  15. export variable from javascript file
  16. export variable from function bash
  17. export variable from function powershell
  18. export variable from simulink to matlab
  19. export variable from file bash
  20. export variable from r

I have an array in php which i am getting in Javascript. Here is my php code $query = "SELECT SeatNum FROM `$busNum` WHERE AB = 1"; $runQuery = mysqli_query($con, $query); $i = 0; foreach($runQuery ...

I have an array in php which i am getting in Javascript. Here is my php code $query = "SELECT SeatNum FROM `$busNum` WHERE AB = 1"; $runQuery = mysqli_query($con, $query); $i = 0; foreach($runQuery ...

Like in array destructuring we can do something like this: let [, b] = [1, 2, 3, 4, 5] so why not foo(, b)?

Like in array destructuring we can do something like this: let [, b] = [1, 2, 3, 4, 5] so why not foo(, b)?