When we code, we usually have a list of object or arrays manipulation.

In the older days, we usually use the classic loop- for, while,do-while


for(...){...} 
while(...){...} 
do{...}while(...)

Nothing is wrong with that, in fact some argue is more performant savvy to manage the iteration that way.

As we progress along, we have some plugins or wrapper that help us write a litte less.
Some example would be like forEach, jquery, loadash.

In today’s modern landscape of dev, syntactic sugars, Es6/Typescript and Arrow function like lambda expression is favored because it is more concise, offers cleaner code for reading and achieve same things with less code written.

**The general idea today is whenever we can, we
discourage coding with this format below for list or object


for(){}

and instead we should leverage the formats of..


arrList.filter/map/sort/findIndex/find()
Object.keys.filter/map/sort/findIndex/find()

Below we some general list manipulation.

Finding a needle item in a list haystack with list.find


const result = listArray.find((item)=>{return item['targetKeyName'] == 'targetKeyValue'});

Finding a needle item’s index in a list haystack with list.findIndex


const result = listArray.findIndex((item)=>{return item['targetKeyName'] == 'targetKeyValue'});

Filter broken needles/items in a list haystack via list.filter


const result = listArray.filter((item)=>{return item['targetKeyName'] != 'broken'});

Remap all the needles/items format in a list haystack using list.map


const result = listArray.map((item)=>{
         const newValue =item.targetKeyName + 1 ;
         const newItem ={'newKeyName' : newValue}
         return newItem;
});

In this working plunk shows a full example of list manipulation with descriptions.


Syntactic sugar helps productivity by helping developer read and understand code faster and write less to achieve more. Es6/ Typescript arrow functions possess this characteristics. Always ensure you have polyfill or any equivalent fallback for older browsers to support


If you enjoy , please share and comment. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *