4.0.1 • Published 2 years ago

aarray v4.0.1

Weekly downloads
8
License
MIT
Repository
github
Last release
2 years ago

Sortable associative array

Changelog

2022-04-20

  • Added function slice
  • Support for nodejs < 6 disabled
  • Typescript
  • object like loop (for (var i in ....))

Dokumentation

Properties

  • length (element count)
  • size (alias for length and Map compatibility)

Functions

  • constructor(Object|Array|AArray|Map)
  • extend (Object|Array|AArray|Map)
  • remove(mixed key)
  • Number nextKey() get next available key
  • mixed push(mixed value, mixed key) key is optional, result is key
  • forEach(Function eachFunction(mixed value, mixed, key, AArray context))
  • Object shiftObject() Result ist {key:mixed, value:mixed}
  • sort(Function f)
  • ksort(Function f)
  • reverse()
  • slice()
  • Array keys()
  • Array values()
  • set(key, value)
  • mixed get(key)

Examples

var mydata = new AArray({'c':'3', 'b':'2', 'a':'1'});
for (var i in mydata) {
	console.info(i+':'+mydata[i]);
}
// Output:
// c:3
// b:2
// a:1

mydata.sort();
for (var i in mydata) {
	console.info(i+':'+mydata[i]);
}
// Output:
// a:1
// b:2
// c:3

mydata.ksort();
for (var i in mydata) {
	console.info(i+':'+mydata[i]);
}
// Output:
// a:1
// b:2
// c:3
var AArray = require("aarray");
var mydata = new AArray();

// assign
mydata['abc'] = 'xyz';
mydata[1] = 'xyz';
var newIndex = mydata.push('xyz');
mydata.push('xyz', 'abc'); // replace first item

// loop
mydata.forEach(function(val, key, context) {
    // do somthing
    // remove item? No problem
    mydata.remove(key) // or delete mydata[key];
});

// loop method 2
for(var key in mydata) {
	console.info(i, mydata[i]);
}
4.0.1

2 years ago

4.0.0

2 years ago

3.0.2

6 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago