@bilalkhanpro/superjs
v0.0.26
Published
Improving existing js Objects with easy usage
Downloads
54
Maintainers
Readme
Array/Object Enhancments
Did you miss array.remove(0)
or array.remove("item3")
function then your desire is full fill now by installing this package.
npm i @bilalkhanpro/superjs
import UpgradeJs from '@bilalkhanpro/superjs';
UpgradeJs();
Usage
Array Usage
Remove By Value
Array.remove
case sensitive function
const userNames = ["Bilal", "Ahsan", "Waheed", "Arsalan"];
userNames.u_remove("Waheed");
Remove By Index
Provide negative number for removing item in reverse order
const userNames = ["Bilal", "Ahsan", "Waheed", "Arsalan"];
userNames.u_removeAt(2);
Object Usage
Now you don't have to use either of the following methodologies:-
Object.keys(obj).length
to calculate length of an object,Object.keys(obj)
to extract keys from an object,Object.values(obj)
to extract values from an object,
Now you can directly use properties like length
, keys
, values
rather than above complax ways
Object Length
const userDetails = {name:"bilal", qualification:"BS", country:"Pakistan"};
userDetails.length;
Object Keys
const userDetails = {name:"bilal", qualification:"BS", country:"Pakistan"};
userDetails.keys;
Object values
const userDetails = {name:"bilal", qualification:"BS", country:"Pakistan"};
userDetails.values;
Object map function
const userDetails = {name:"bilal", qualification:"BS", country:"Pakistan"};
const tempMapObj = userDetails.umap((key,value,index)=>{
console.log("key::", key," value::", value, " index::", index)
return value;
})
console.log(tempMapObj);
// *output :*
// key:: name value:: bilal index:: 0
// key:: qualification value:: BS index:: 1
// key:: country value:: Pakistan index:: 2
// [ 'bilal', 'BS', 'Pakistan' ]