Skip to main content

Posts

Showing posts from July, 2020

Using map(), reduce() and filter() array methods to nail Javascript manipulation

While working on a real life project we often have front end separated from backend by API, which is a standard modern method as of today. But the data given by backend API is not always favorable for the frontend. And such scenario in real life is imminent and it is not always possible to write a new API for every desirable data in frontend which can be manipulated. But this scenario is not necessarily only useful on frontend, but also could prove very significant on backend too.  map  creates a new array by transforming every element in an array, individually.  filter  creates a new array by removing elements that don't belong.  reduce , on the other hand, takes all of the elements in an array, and  reduces  them into a single value. map → Executes a function on each element of an array filter → Remove items which don’t satisfy a condition Reduce → Creates a single value from elements of Array Array.prototype.map() The  map()  method  ...

Instant search with Vue js and axios using filter in computed property.

Vue js is an excellent framework. It's main beauty lies in its reactivity. Its reactivity can be used to solve many problems from the frontend without having to write additional routes on backend api. This post demonstrates how can we use vue js reactivity to make an instant search as you type using the filter method in computed property. There are few things you should know about vue js before jumping into this post. Vue reactivity  Vue lifecycle Http request using axios Rest API (also Fake Rest API) I am writing this blog for future reference for myself but in the meantime it could be useful for anyone, especially beginners like me. Now, lets make an instant search input box to filter data that comes from Lorem Picsum Web API. The Lorem Picsum web API gives response in following format. [ { " id " : " 10 " , " author " : " Paul Jarvis " , " width " : 2500 , " height " : 1667 , " url ...