2016-10-26 16 views
1

私は配列を持っていますが、私は異なる値のために異なる配列を作りたいと思います。これは私の配列ですjavascriptを格納する配列

var data = [{ 
     "rateType": "Fixed", 
     "interestRateMin": "12.0", 
     "imageUrl": "\/images\/dyn\/null.jpg", 
     "financingPercentageMax": "80", 
     "interestRateMax": "12.0", 
     "prePaymentCharge": "Nil", 
     "financingPercentageMin": "60", 
     "bankName": "Muthoot Finance", 
     "security": "Pledge of the gold ornaments and coins.", 
     "repaymentTenureInYears": "0.25", 
     "age": "35", 
     "processingFee": "Nil", 
     "maxLoanAmt": "10000000" 
    }, { 
     "rateType": "Floating", 
     "interestRateMin": "12.5", 
     "imageUrl": "\/images\/dyn\/94.jpg", 
     "financingPercentageMax": "90", 
     "interestRateMax": "12.5", 
     "prePaymentCharge": "DNA", 
     "financingPercentageMin": "75", 
     "bankName": "Federal Bank- Gold loan", 
     "security": "DNA", 
     "repaymentTenureInYears": "1", 
     "age": "35", 
     "processingFee": "DNA", 
     "maxLoanAmt": "7500000" 
    }, { 
     "rateType": "Floating", 
     "interestRateMin": "13.0", 
     "imageUrl": "\/images\/dyn\/155.jpg", 
     "financingPercentageMax": "80", 
     "interestRateMax": "13.0", 
     "prePaymentCharge": "DNA", 
     "financingPercentageMin": "80", 
     "bankName": "State Bank of Travancore- Liquid loan", 
     "security": "Pledge of gold ornaments", 
     "repaymentTenureInYears": "1", 
     "age": "35", 
     "processingFee": "DNA", 
     "maxLoanAmt": "1000000" 
    }, { 
     "rateType": "Floating", 
     "interestRateMin": "13.25", 
     "imageUrl": "\/images\/dyn\/151.jpg", 
     "financingPercentageMax": "80", 
     "interestRateMax": "13.25", 
     "prePaymentCharge": "DNA", 
     "financingPercentageMin": "80", 
     "bankName": "State Bank Of Hyderabad- Overdraft", 
     "security": "Pledge of Gold ornaments or Jewellery made of 22 Carat or 18 Carat", 
     "repaymentTenureInYears": "3", 
     "age": "35", 
     "processingFee": "1.10% of the original limit or max Rs 330", 
     "maxLoanAmt": "1500000" 
    }, { 
     "rateType": "Floating", 
     "interestRateMin": "14.5", 
     "imageUrl": "\/images\/dyn\/161.jpg", 
     "financingPercentageMax": "80", 
     "interestRateMax": "14.5", 
     "prePaymentCharge": "DNA", 
     "financingPercentageMin": "80", 
     "bankName": "Lakshmi Vilas Bank", 
     "security": "Pledge of gold ornaments", 
     "repaymentTenureInYears": "1", 
     "age": "35", 
     "processingFee": "0.50% of the limit sanctioned, min Rs 100", 
     "maxLoanAmt": "5000000" 
    }]; 

すべてのrateTypeを1つの配列に保存します。このように私は他の要素を格納するために別の配列を作成したい。誰かがあなたがdataオブジェクトに(例えば)rateTypeの配列を取得したい場合は、あなたがこれを行うことができ、この

+0

この配列を反復処理し、[rateType]値で新しい配列を作成するにはどうすればよいですか? –

+0

もっと説明できますか?新しい配列には何が含まれていますか? – cjohansson

+0

['Array.prototype.filter()'](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)を使用してください。 – str

答えて

1

に私を導くことができる:

var data=[{rateType:"Fixed",interestRateMin:"12.0",imageUrl:"/images/dyn/null.jpg",financingPercentageMax:"80",interestRateMax:"12.0",prePaymentCharge:"Nil",financingPercentageMin:"60",bankName:"Muthoot Finance",security:"Pledge of the gold ornaments and coins.",repaymentTenureInYears:"0.25",age:"35",processingFee:"Nil",maxLoanAmt:"10000000"},{rateType:"Floating",interestRateMin:"12.5",imageUrl:"/images/dyn/94.jpg",financingPercentageMax:"90",interestRateMax:"12.5",prePaymentCharge:"DNA",financingPercentageMin:"75",bankName:"Federal Bank- Gold loan",security:"DNA",repaymentTenureInYears:"1",age:"35",processingFee:"DNA",maxLoanAmt:"7500000"},{rateType:"Floating",interestRateMin:"13.0",imageUrl:"/images/dyn/155.jpg",financingPercentageMax:"80",interestRateMax:"13.0",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"State Bank of Travancore- Liquid loan",security:"Pledge of gold ornaments",repaymentTenureInYears:"1",age:"35",processingFee:"DNA",maxLoanAmt:"1000000"},{rateType:"Floating",interestRateMin:"13.25",imageUrl:"/images/dyn/151.jpg",financingPercentageMax:"80",interestRateMax:"13.25",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"State Bank Of Hyderabad- Overdraft",security:"Pledge of Gold ornaments or Jewellery made of 22 Carat or 18 Carat",repaymentTenureInYears:"3",age:"35",processingFee:"1.10% of the original limit or max Rs 330",maxLoanAmt:"1500000"},{rateType:"Floating",interestRateMin:"14.5",imageUrl:"/images/dyn/161.jpg",financingPercentageMax:"80",interestRateMax:"14.5",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"Lakshmi Vilas Bank",security:"Pledge of gold ornaments",repaymentTenureInYears:"1",age:"35",processingFee:"0.50% of the limit sanctioned, min Rs 100",maxLoanAmt:"5000000"}]; 
 

 
var result = []; 
 

 
data.forEach(function(element){ 
 
    this.push(element.rateType); 
 
}, result); 
 

 
console.log(result);

私は」 forEachメソッドのthisArgを使用して新しい配列を作成します。

乾杯!

+1

ありがとうございます@kukkuz – user6924814