Is there a way to filter items in a table?

Hi

I have a question if it is possible to filter a table based on an item’s data. e.g.

local myTable = { {img="apple.png", name="apple",status="1"}, {img="orange.png", name ="orange"}, {img="pineapple.png",name="pineapple"}, {img="papaya.png",name="papaya"}, {img="watermelon.png",name="watermelon",status="1"}, {img="durian.png",name="durian"}, }

I can sort with status=“1” but it still gives me all the items. 

I just want apple and watermelon. 

Is this possible? or anyone has an idea how to do this. 

I figured one way is to sort and then create another table with just apple and watermelon , but seems like an inefficient way. 

Thanks.

TH

Like this

local rowNums={} for i=1,#myTable do if myTable[i].status and myTable[i].status=="1" then rowNums[#rowNums+1] = i end end for i=1,#rowNums do print("this is row:"..rowNum[i].."and my name is "..myTable[rowNum[i]].name) end

Hi Scotrules44

thanks for the tip. Creating a separate index table to it is a nice idea.

Rgds

TH

Like this

local rowNums={} for i=1,#myTable do if myTable[i].status and myTable[i].status=="1" then rowNums[#rowNums+1] = i end end for i=1,#rowNums do print("this is row:"..rowNum[i].."and my name is "..myTable[rowNum[i]].name) end

Hi Scotrules44

thanks for the tip. Creating a separate index table to it is a nice idea.

Rgds

TH