Has
Has

Reputation: 13

combine two return statements into one

i have the following code:

 const Test = obj && obj.length > 0 && obj.map((myguids2, key) => {
    const url2 = myguids2.predicatList.map(mypredicats => {
        const url = mypredicats.p
        var arr = url.split('/')[3]
        return ( 
                            <div>{arr}</div>
                )
    })
    const content = myguids2.guidList.map((myqueriedguids, key) => {
        return (
            <tr>
                 <td>{myqueriedguids.guid.includes('http://linkedbuildingdata.net/ifc/resources20201208_005325/') ? <MyPopUp myproperties={guidList} myguidnames={myqueriedguids.guid}>{myqueriedguids.guid}</MyPopUp> : myqueriedguids.guid}</td>
            </tr>
            )
    })
    return content

})

i want to combine the output from url2 with the output coming from content into a two column table with url2 in the left table column and content in the right table

is there way to structure the function in such a way?

Upvotes: 0

Views: 304

Answers (2)

Has
Has

Reputation: 13

So the best way for now is to split the Const Test into two variables one containing the url2 and one the content. using a return statement i managed to put {url2} : {Test} to gain the two column output

Upvotes: 0

underscore
underscore

Reputation: 6877

Just return an object

const Test = obj && obj.length > 0 && obj.map((myguids2, key) => {
        const url2 = myguids2.predicatList.map(mypredicats => {
            const url = mypredicats.p
            var arr = url.split('/')[3]
            return ( 
                                <div>{arr}</div>
                    )
        })
        const content = myguids2.guidList.map((myqueriedguids, key) => {
            return (
                <tr>
                     <td>{myqueriedguids.guid.includes('http://linkedbuildingdata.net/ifc/resources20201208_005325/') ? <MyPopUp myproperties={guidList} myguidnames={myqueriedguids.guid}>{myqueriedguids.guid}</MyPopUp> : myqueriedguids.guid}</td>
                </tr>
                )
        })
        return { content, url2  }
    
    })

Then you can access properties by

Test.content or Test.url2

Upvotes: 1

Related Questions