What Is RxJs?

Aslı Küçükakarsu
Logiwa Tech
Published in
4 min readSep 30, 2022

--

https://www.indellient.com

It is a reactive programming library coded with JavaScript, where you can convert the data sources into subscribable objects and perform conversions on these objects with the help of the operators.

These utility functions can be used for:
• Converting existing code for async operations into observables
• Iterating through the values in a stream
• Mapping values to different types
• Filtering streams
• Composing multiple streams

I would like to provide some rxjs methods and operations with simple examples that everyone can easily understand.

map()

After making the desired changes in an array, it allows the mapping of the last state of the array to another array.

We have circulated all elements of Array arr with mapping to add 2 and assigned the result to another array.

reduce()

It returns a single result according to the given condition, the return value is kept in the accumulator parameter, which is the first parameter.

We have calculated the sum of all element values in the array with reduce method.

find()

It returns the first array element that meets the condition. If no element meets the condition, it returns undefined.

For example, here, it will return undefined since no array element meets the condition.

findIndex()

It returns the index number of the array element that meets the condition.

Since the first element that meets the condition is 12, it returned the index number of 12 as output.

filter()

It filters the elements in the array depending on the determined condition. If elements are meeting the condition, it returns, if not, it returns a null array.

We have filtered the numbers equal to or less than 10 in the array.

push()

The Push Method allows us to add new elements to the end of the array.

Since we directly add the element to the array itself with the Push Method, there is no need to assign a new element to the array just like in other examples. If you assign it a new array, you will see that the print of the return will provide you with the length of the array :)

concat()

It allows you to combine two or more arrays. The existing arrays will not change, and they return a newly merged array output.

As it can be seen here, arrays arr1 and arr2 remain the same. We have assigned the merging process to a new array. Thus, we have three arrays now.

join()

It combines the array elements with a determined bracket. It returns a string.

foreach()

It lets you cycle the array. It allows you to perform actions on each element.

We circulated the entire elements of the array and increased the counter by one by finding the ‘Hello’ word. Since there are two ‘Hello’ elements in the array, the counter returned the value of 2.

includes()

The Includes method checks whether a determined value is available in the array or not. If the value matches, it returns a boolean.

Since we have provided a value that is not available in the array, we received the false statement. If we would type any of the elements of the array, it would be true.

I wanted to share the functions of rxjs methods with basic examples. I hope, they are clear and easy-to-get. You can use these methods in more complicated data structures and structure the data in any desired format.

Reference:https://rxjs.dev/api

--

--