Methods
(inner) getKeyNameByValue(obj, value) → {string}
Get Key name of a value from Object
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | |
value |
string | number |
- Source:
Returns:
Object key name based on passed value
- Type
- string
Example
getKeyNameByValue({name: "Person", age: 30}, 30);
// return age
getKeyNameByValue({name: "Person", age: 30}, 'Person');
// return name
getKeyNameByValue({name: "Person", age: 30}, 'age');
// return null
(inner) isObject(data) → {boolean}
Check if passed data is an valid Object
Parameters:
Name | Type | Description |
---|---|---|
data |
any | Data to be validate |
- Source:
Returns:
true | false
- Type
- boolean
Example
// Calls the `isObject` function to validate data
isObject([1,2,3])
// return false
isObject('This is a string')
// return false
isObject({name: Array})
// return true
isObject(null)
// return false
isObject(undefined)
// return false
(inner) removeObjFromArray(arrOfObj, id) → {Array}
Remove an object from array based on id
Parameters:
Name | Type | Description |
---|---|---|
arrOfObj |
Arra.<Object> | |
id |
string | number |
- Source:
Returns:
New Array with updated Objects
- Type
- Array
Example
const arr = [{name: "Test", Loc: "Anywhere", id: 1, area: "Delhi"},
{id: 2, name: "User", location: "Delhi"}];
removeObjFromArray(arr, 1);
// return [{id: 2, name: "User", location: "Delhi"}]
(inner) renameObjKeys(keysMap, obj) → {Object}
Replaces the names of multiple object keys with the values provided
Parameters:
Name | Type | Description |
---|---|---|
keysMap |
Object | |
obj |
Object |
- Source:
Returns:
New object with updated key names
- Type
- Object
Example
const obj = { name: 'John', job: 'Front-End Master', shoeSize: 100 };
renameObjKeys({ name: 'firstName', job: 'passion' }, obj);
// return { firstName: 'John', passion: 'Front-End Master', shoeSize: 100 }
(inner) sliceObjectKeys(object, keys) → {Object}
Get trimmed Object based on Keys
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | |
keys |
Array.<string> |
- Source:
Returns:
New object with passed keys
- Type
- Object
Example
const Obj = {name: "Test", Loc: "Anywhere", id: 1, area: "Delhi"}
sliceObjectKeys(Obj, ['Loc'])
// return {Loc: "Anywhere"}
sliceObjectKeys(Obj, ['Loc', "id", "name"])
// return {name: "Test", Loc: "Anywhere", id: 1}