Posts

Showing posts from March, 2020

To find array index of complex

<aura:component >          <aura:handler name="render" value="{!this}" action="{!c.myAction}"/>     <aura:attribute name="objs" type="Object[]" /> </aura:component> ({ myAction : function(component, event, helper) { var studentsArray =      [     {     "rollnumber": 1,     "name": "dj",     "subject": "physics"    },    {    "rollnumber": 2,   "name": "tanmay",   "subject": "biology"    },   {    "rollnumber": 3,    "name": "amit",    "subject": "chemistry"    },                   ];            console.log('studentsArray'+JSON.stringify(studentsArray[0]));         console.log(studentsArray[0].rollnumber);   console.log(studentsArray[0].name...

javascript to search array of object

var studentsArray = [ { "rollnumber" : 1 , "name" : "dj" , "subject" : "physics" }, { "rollnumber" : 2 , "name" : "tanmay" , "subject" : "biology" }, { "rollnumber" : 3 , "name" : "amit" , "subject" : "chemistry" }, ]; function functiontofindIndexByKeyValue ( arraytosearch , key , valuetosearch ) { for ( var i = 0 ; i < arraytosearch . length ; i ++) { if ( arraytosearch [ i ][ key ] == valuetosearch ) { return i ; } } return null ; } var index = functiontofindIndexByKeyValue ( studentsArray , "name" , "tanmay" ); alert ( index ); function getIndex ( val ) { for ( var i = 0 ; i < imageList . length ; i ++) { if ( imageList [ i ] ...

Array to push element to array

mpex_app.app <aura:application extends="force:slds">   <c:mpex1></c:mpex1> </aura:application> CMP <aura:component>   <aura:attribute name="objs" type="Object[]" />   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />   <table>     <tr>       <th>Product</th>       <th>Price</th>     </tr>     <aura:iteration items="{!v.objs}" var="obj">       <tr>         <td>{!obj.product}</td>         <td>{!obj.price}</td>       </tr>     </aura:iteration>   </table>   <!-- component B -->   <lightning:button variant="brand" label="Add another" title="Brand action" onclick="{! c.handleClick }" /> </aura:component> JS ({ ...