Skip to main content
Rollback to Revision 1
Source Link
Geuis
  • 42.5k
  • 57
  • 164
  • 223

The terminology in js can be confusing at first, so lets straighten that out first.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it'sits different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. TheThe keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, thatThis increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let'sLets talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays. So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

The terminology in js can be confusing at first, so lets straighten that out.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, that increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

The terminology in js can be confusing at first, so lets straighten that out first.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but its different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, This increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Lets talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

denoise https://meta.stackexchange.com/q/131009/997587
Source Link
starball
  • 59.6k
  • 52
  • 314
  • 1k

The terminology in js can be confusing at first, so lets straighten that out.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, that increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

The terminology in js can be confusing at first, so lets straighten that out.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, that increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

The terminology in js can be confusing at first, so lets straighten that out.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, that increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

added 1 characters in body
Source Link
Adam Rackis
  • 83.5k
  • 57
  • 281
  • 402

The terminology in js can be confusing at first, so lets straighten that out first.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but itsit's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, Thisthat increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

LetsLet's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

The terminology in js can be confusing at first, so lets straighten that out first.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but its different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, This increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Lets talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

The terminology in js can be confusing at first, so lets straighten that out.

Yes, pretty much everything in js is an object. However, there are differences in the data types.

An array can be used like as associative array, but it's different than an object literal.

var x = []; //array var y = {}; //object literal 

An array is like a list. The keys of an array can be a numerical index or a string.

var x = ['a','b']; // x[0] === 'a', x[1] === 'b'; var x = []; x['one'] = 'a'; x['blah'] = 'b'; 

Object literals are like dictionaries. They can be used in a similar way.

var x = { 0: 'a', 1: 'b' }; var x = { one: 'a', two: 'b' }; 

However, this is where you need to understand the differences.

You can use an array like an object literal, but you can't use an object literal quite like an array.

Arrays have the automated "length" property, that increments and decrements automatically based on the total number of elements in the array. You don't get this with object literals. Arrays also get all of the other array-specific methods like shift, unshift, splice, pop, push, etc. Object literals don't have those methods.

Let's talk about delete and what happens on an array and on an object literal.

var x = ['a', 'b']; //["a", "b"] delete x[0]; //[undefined, "b"] var x = {0:'1', 1:'b'}// { 0:"1", 1:"b"} delete x[0]; // { 1:"b" } 

If you perform a delete on an element of an array, the length of the array doesn't change. The element index is preserved and the value is set to 'undefined';

Conversely, performing a delete on an object literal removes the key/value from the object.

Finally, if you want to remove an element from an array.

var x = ['a', 'b']; x.splice(0,1); //modifies x. ['b'] 

So, in summary use delete on object literals. Use splice on arrays.

Hope this helps.

Source Link
Geuis
  • 42.5k
  • 57
  • 164
  • 223
Loading