Better method?

Is there a better way in which I can find number of values in a table which have a specific value.

function setup()
    t={}
    for i=1,10 do
        t[i]=math.random(1,10)
    end
    
    Not={}
    for k,v in pairs(t) do
        if v==1 then
            table.insert(Not,v)
        end
    end
    print(#Not) --number of values in table(t) which have value 1
end 

I tried this method. One more thing. How or mor precisely when exactly is table.concat used. If it changes a table to string… I can’t understand how it can be used.

Instead of table.insert(not,v), why not just n=n+1

table.concat can be used when storing table data locally (because it has to be a string or value), or it can be used to pass a set of parameters to a function.

Oh yeah thanks!!

Table.concat is very useful when you do heavy word processing in codea, like working with a full project as text. Each string is a newly created one in lua. So if you add many littles pieces (lines for ex) to a big text string, the full text will be recreated each time: it can take a lot of memory and time in the end. A much better way is to store each line in a table t[i], and when you are finished with what you want to do, convert this table of lines in one big string, with concat, using the separator you want (‘\r’ for line return for instance), and then do what you want with this string (send to github, …).

I think I can see how it’ll be useful. Thanks!!