5.0.0 • Published 9 months ago

aarray v5.0.0

Weekly downloads
8
License
MIT
Repository
gitlab
Last release
9 months 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 = 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 = 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]);
}
5.0.0

9 months ago

4.0.5

9 months ago

4.0.4

9 months ago

4.0.3

9 months ago

4.0.2

9 months ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.2

7 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.2.0

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago