Navigate back to the homepage

how to check array or not in typescript?

Infinitbility
TypeScript
September 3rd, 2022 · 1 min read
how to check array or not in typescript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To check array or not in typeScript, use Array.isArray() method it will true or false based on value we have provided, even it’s detect between object or instance of array.

Let’s see short example to use if...else with Array.isArray() to check array or not in typeScript.

1if(Array.isArray(array)){
2
3}

Today, I’m going to show you How do I check array or not in typeScript, as above mentioned, I’m going to use the above-mentioned if...else method with Array.isArray().

Let’s start today’s tutorial how do you check array or not in typeScript?

TypeScript check array or not example

Here, we will take string variable with some data and use if...else method with Array.isArray() to check array or not.

1let arr: Array<string> = ["infinitbility"];
2
3if(Array.isArray(arr)){
4 console.log("arr is array")
5} else {
6 console.log("arr is not array")
7}
8
9interface user {
10 id: number,
11 name: string
12}
13
14let obj: user = {
15 id: 1,
16 name: 'infinitbility'
17};
18
19if(Array.isArray(obj)){
20 console.log("obj is array")
21} else {
22 console.log("obj is not array")
23}

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to get string after last slash in javascript?

how to get string after last slash in javascript?

An example of get string after last slash in javascript with the step-by-step guide.

August 29th, 2022 · 1 min read
how to get string after dot in javascript?

how to get string after dot in javascript?

An example of get string after dot in javascript with the step-by-step guide.

August 28th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]