Soup.mapKeys() - shysolocup/stews GitHub Wiki
overwrites all keys with something
type: Function
alt names:
- mapKey()
arguments:
- mapper
Function
:
goes through every entry with the function and replaces the key with the return value
see Soup.forEach() for more info
list: | pair: |
const { Soup } = require('stews');
let arr = new Soup([ "abc", "def" ]);
console.log(arr.mapKeys( (v, i) => {
return `${v} ${ 123 * (i+1) }`;
})); |
const { Soup } = require('stews');
let obj = new Soup({ x: "val1", y: "val2" });
console.log(obj.mapKeys( (k, v, i) => {
return `key${i}`;
})); |
Soup(2) [ "abc 123", "def 246" ] |
Soup(2) { key1: "val1", key2: "val2" } |