Home > Mobile >  How to get all values in a data table
How to get all values in a data table

Time:11-14

I am trying to get all the values in a javascript data table but whenever I try it says table.length is not a function or table.size is not a function (I've tried both). Here is the code I want to use

const wordcount = {"this", "is", "a", "data", "table"}

console.log(wordcount.size()) // wordcount.size is not a function

I want it to return an integer value to the console. How would I do this?

CodePudding user response:

Word count is not an valid array, see the code below it should work fine

const wordCount = ['this', 'is', 'a', 'data', 'table']

console.log(wordCount.length)

An array should always start with this '[' and end with this ']' not with '{'

I Hope this is helpful to you

CodePudding user response:

I think I got your question wrong are you trying to make a data table? A data table must only contain primitive values such as string, number, Boolean, null, undefined etc.

// sample code 
const data = {
   name: "Jhon",
   age: 25,
   isChild: false,
 }

Note: size is not a function it is an attribute

  • Related