Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重新格式化数组_Javascript_Arrays - Fatal编程技术网

Javascript 重新格式化数组

Javascript 重新格式化数组,javascript,arrays,Javascript,Arrays,我想从for循环中的3个数组中获取元素(每个数组有11个元素) 非常感谢您的回复,但我有一个错误:“超过了最大调用堆栈大小” 我真的是个新手 这是全部代码: // Listen for submit document.getElementById("simulateur-form").addEventListener("submit", computeResults); function computeResults(e) { // Récupération des données

我想从for循环中的3个数组中获取元素(每个数组有11个元素)

非常感谢您的回复,但我有一个错误:“超过了最大调用堆栈大小”

我真的是个新手

这是全部代码:

// Listen for submit
document.getElementById("simulateur-form").addEventListener("submit", computeResults);

function computeResults(e) {

    // Récupération des données
    const UIamount = parseInt(document.getElementById("montant-total-projet").value);  
    const UIapport = parseInt(document.getElementById("apport").value);
    const UIinterest = parseFloat(document.getElementById("taux-pret").value);
    const UIinterestassurance = parseFloat(document.getElementById("taux-assurance").value);
    const UIyears = parseInt(document.getElementById("annee").value);


    //Compute monthly Payment
    const x = Math.pow(1 + (parseFloat(UIinterest) / 100 / 12), (parseFloat(UIyears) * 12));
    const monthly = (parseFloat(UIamount-UIapport) * x * (parseFloat(UIinterest) / 100 / 12)) / (x - 1);
    const monthlyPayment = monthly.toFixed(2);

    // Assurance
    const monthlyPaymentAssurance = ((parseFloat(UIinterestassurance) / 100 / 12)*(UIamount - UIapport)).toFixed(2);
    const totalPaymentAssurance = (monthlyPaymentAssurance * (parseFloat(UIyears) * 12)) ;

    // Mensualité totale
    const mensualitetotale = parseFloat(monthlyPaymentAssurance) + parseFloat(monthlyPayment);

    //Intérêts
    const totalInterest = (monthly * (parseFloat(UIyears) * 12) - parseFloat(UIamount-UIapport)).toFixed(2);

    // Cashflow
    const cashflow = (10858 - mensualitetotale);

    // Coût total
    const coutTotal = (parseFloat(UIamount) + parseFloat(totalInterest) + parseFloat(totalPaymentAssurance)).toFixed(2);

    //Formattage des résultats et affichage
    const UIamount1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(coutTotal)); 
    document.getElementById("UIamount1").innerHTML =  UIamount1;    
    const monthlyPayment1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyPayment));
    document.getElementById("monthlyPayment1").innerHTML = monthlyPayment1;
    const totalPaymentAssurance1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalPaymentAssurance));
    document.getElementById("totalPaymentAssurance1").innerHTML = totalPaymentAssurance1;
    const mensualitetotale1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(mensualitetotale));
    document.getElementById("mensualitetotale1").innerHTML = mensualitetotale1;
    const cashflow1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(cashflow));
    document.getElementById("cashflow1").innerHTML = cashflow1;
    const monthlyPaymentAssurance1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyPaymentAssurance));
    document.getElementById("monthlyPaymentAssurance1").innerHTML = monthlyPaymentAssurance1;
    const totalInterest1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalInterest));
    document.getElementById("totalInterest1").innerHTML = totalInterest1;


    var anneesListe = new Array(11);
    var mensualitepretListe = new Array(11);
    var mensualiteAssuranceListe = new Array(11);
    var coutTotalAssuranceListe = new Array(11);
    var coutTotalInteretListe = new Array(11);
    var mensualiteTotaleListe = new Array(11);  
    var coutProjetListe = new Array(11); 
    var cashflowListe = new Array(11); 


  var NBmois = (UIyears * 12);
for(var i= (UIyears - 5); i< UIyears + 6; i++)
    {
var anneesListelenght = anneesListe.push(i+ " ans");
var mensualitepretListelenght = mensualitepretListe.push(((UIamount - UIapport) * x * (parseFloat(UIinterest) / 100 / 12)) / (x-1));
var mensualiteAssuranceListelenght = mensualiteAssuranceListe.push((parseFloat(UIinterestassurance) / 100 / 12) * (UIamount - UIapport));
var coutTotalAssuranceListelenght = coutTotalAssuranceListe.push(monthlyPaymentAssurance * NBmois);
var coutTotalInteretListelenght = coutTotalInteretListe.push(monthlyPayment * NBmois - (UIamount - UIapport));
var mensualiteTotaleListelenght = mensualiteTotaleListe.push(monthlyPayment + monthlyPaymentAssurance);
var coutProjetListelenght = coutProjetListe.push(UIamount + totalPaymentAssurance + totalInterest);
var cashflowListelenght = cashflowListe.push(10858 - mensualitetotale);
}







// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("graphsimu", am4charts.XYChart);

chart.numberFormatter.intlLocales = "fr_FR";

// Data for both series
var data =  [
  { Durée: "10 ans", "Mensualité": 5400,  "Coût total du crédit": 49000},
  { Durée: "11 ans", "Mensualité": 5000, "Coût total du crédit": 54000 },
  { Durée: "12 ans", "Mensualité": 4600, "Coût total du crédit": 60000 },
  { Durée: "13 ans", "Mensualité": 4300, "Coût total du crédit": 70000 },
  { Durée: "14 ans", "Mensualité": 4000, "Coût total du crédit": 75000 },
  { Durée: "15 ans", "Mensualité": 3800, "Coût total du crédit": 84000 },
  { Durée: "16 ans", "Mensualité": 3650, "Coût total du crédit": 90000 },
  { Durée: "17 ans", "Mensualité": 3600, "Coût total du crédit": 98000 },
  { Durée: "18 ans", "Mensualité": 3400, "Coût total du crédit": 108000 },
  { Durée: "19 ans", "Mensualité": 3200, "Coût total du crédit": 115000 },
  { Durée: "20 ans", "Mensualité": 3000, "Coût total du crédit": 124000 },
];

/* Create axes */
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Durée";
categoryAxis.renderer.minGridDistance = 30;


/* Create value axis */
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var valueAxis2 = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis2.renderer.opposite = true;
valueAxis2.syncWithAxis = valueAxis;


var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryX = "Durée";
series.dataFields.valueY = "Mensualité";

series.columns.template.tooltipY = 0;
series.columns.template.strokeOpacity = 0;


var lineSeries = chart.series.push(new am4charts.LineSeries());
lineSeries.dataFields.valueY = "Coût total du crédit";
lineSeries.dataFields.categoryX = "Durée"; 
lineSeries.stroke = am4core.color("#880000");
lineSeries.strokeWidth = 3;
lineSeries.yAxis = valueAxis2;



var bullet = lineSeries.bullets.push(new am4charts.Bullet());

var circle = bullet.createChild(am4core.Circle);
circle.radius = 4;
circle.fill = am4core.color("#880000");
circle.strokeWidth = 3; 
chart.data = data;


/* Add a single HTML-based tooltip to first series */
series.tooltipText = `[bold] {Durée}[/]
----
Mensualité : [bold]{Mensualité} €[/]
Coût total du crédit : [bold]{Coût total du crédit} €[/]`;
series.tooltip.pointerOrientation = "vertical";





// as by default columns of the same series are of the same color, we add adapter which takes colors from chart.colors color set
series.columns.template.adapter.add("fill", function(fill, target) {
  return chart.colors.getIndex(target.dataItem.index);
});

/* Create a cursor */
chart.cursor = new am4charts.XYCursor();





  e.preventDefault();
}
//侦听是否提交
文件。getElementById(“模拟器格式”)。添加的文件列表(“提交”,计算机结果);
功能计算机结果(e){
//酒杯
const UIamount=parseInt(document.getElementById(“montant total projet”).value);
const UIapport=parseInt(document.getElementById(“apport”).value);
const UIinterest=parseFloat(document.getElementById(“taux pret”).value);
const uiinterestasurance=parseFloat(document.getElementById(“taux assurance”).value);
const UIyears=parseInt(document.getElementById(“annee”).value);
//计算每月付款
常数x=数学功率(1+(parseFloat(UIinterest)/100/12),(parseFloat(UIyears)*12));
const monthly=(parseFloat(UIamount UIapport)*x*(parseFloat(UIinterest)/100/12))/(x-1);
const monthlyPayment=每月固定(2);
//保证
const monthlyPaymentAssurance=((parseFloat(uiinterestasurance)/100/12)*(UIamount-UIapport)).toFixed(2);
const totalPaymentAssurance=(月度支付保证*(浮动(UIyears)*12));
//总体量表
const mensualitetotale=parseFloat(monthlyPaymentAssurance)+parseFloat(monthlyPayment);
//内特
const totalInterest=(每月*(parseFloat(UIyears)*12)-parseFloat(UIamount UIapport)).toFixed(2);
//现金流
常量现金流=(10858-计量总金额);
//共有
const coutTotal=(parseFloat(UIamount)+parseFloat(totalInterest)+parseFloat(totalPaymentAssurance)).toFixed(2);
//成果和附件的格式
const UIamount1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'}).format(coutTotal));
document.getElementById(“UIamount1”).innerHTML=UIamount1;
const monthlyPayment1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(monthlyPayment));
document.getElementById(“monthlyPayment1”).innerHTML=monthlyPayment1;
const totalPaymentAssurance1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(totalPaymentAssurance));
document.getElementById(“totalPaymentAssurance1”).innerHTML=totalPaymentAssurance1;
const mensualitetotale1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(mensualitetotale));
document.getElementById(“mensualitetotale1”).innerHTML=mensualitetotale1;
const cashflow1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(cashflow));
document.getElementById(“cashflow1”).innerHTML=cashflow1;
const monthlyPaymentAssurance1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(monthlyPaymentAssurance));
document.getElementById(“monthlyPaymentAssurance1”).innerHTML=monthlyPaymentAssurance1;
const totalInterest1=(新的Intl.NumberFormat('de-de',{style:'currency',currency:'EUR'})。格式(totalInterest1));
document.getElementById(“totalInterest1”).innerHTML=totalInterest1;
var anneesListe=新数组(11);
var mensualitepretListe=新数组(11);
var mensualiteasuranceliste=新数组(11);
var coutTotalAssuranceListe=新数组(11);
var coutTotalInteretListe=新数组(11);
var mensualiteTotaleListe=新数组(11);
var coutProjetListe=新数组(11);
var cashflowListe=新数组(11);
var NBmois=(UIyears*12);
对于(变量i=(UIyears-5);ivar data =  [
  { Durée: anneesListe.value1, "Mensualité": mensualiteTotaleListe.value1,  "Coût total du crédit": coutProjetListe.value1},
  { Durée: anneesListe.value2, "Mensualité": mensualiteTotaleListe.value2,  "Coût total du crédit": coutProjetListe.value2},
  { Durée: anneesListe.value3, "Mensualité": mensualiteTotaleListe.value3,  "Coût total du crédit": coutProjetListe.value3},
];
// Listen for submit
document.getElementById("simulateur-form").addEventListener("submit", computeResults);

function computeResults(e) {

    // Récupération des données
    const UIamount = parseInt(document.getElementById("montant-total-projet").value);  
    const UIapport = parseInt(document.getElementById("apport").value);
    const UIinterest = parseFloat(document.getElementById("taux-pret").value);
    const UIinterestassurance = parseFloat(document.getElementById("taux-assurance").value);
    const UIyears = parseInt(document.getElementById("annee").value);


    //Compute monthly Payment
    const x = Math.pow(1 + (parseFloat(UIinterest) / 100 / 12), (parseFloat(UIyears) * 12));
    const monthly = (parseFloat(UIamount-UIapport) * x * (parseFloat(UIinterest) / 100 / 12)) / (x - 1);
    const monthlyPayment = monthly.toFixed(2);

    // Assurance
    const monthlyPaymentAssurance = ((parseFloat(UIinterestassurance) / 100 / 12)*(UIamount - UIapport)).toFixed(2);
    const totalPaymentAssurance = (monthlyPaymentAssurance * (parseFloat(UIyears) * 12)) ;

    // Mensualité totale
    const mensualitetotale = parseFloat(monthlyPaymentAssurance) + parseFloat(monthlyPayment);

    //Intérêts
    const totalInterest = (monthly * (parseFloat(UIyears) * 12) - parseFloat(UIamount-UIapport)).toFixed(2);

    // Cashflow
    const cashflow = (10858 - mensualitetotale);

    // Coût total
    const coutTotal = (parseFloat(UIamount) + parseFloat(totalInterest) + parseFloat(totalPaymentAssurance)).toFixed(2);

    //Formattage des résultats et affichage
    const UIamount1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(coutTotal)); 
    document.getElementById("UIamount1").innerHTML =  UIamount1;    
    const monthlyPayment1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyPayment));
    document.getElementById("monthlyPayment1").innerHTML = monthlyPayment1;
    const totalPaymentAssurance1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalPaymentAssurance));
    document.getElementById("totalPaymentAssurance1").innerHTML = totalPaymentAssurance1;
    const mensualitetotale1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(mensualitetotale));
    document.getElementById("mensualitetotale1").innerHTML = mensualitetotale1;
    const cashflow1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(cashflow));
    document.getElementById("cashflow1").innerHTML = cashflow1;
    const monthlyPaymentAssurance1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyPaymentAssurance));
    document.getElementById("monthlyPaymentAssurance1").innerHTML = monthlyPaymentAssurance1;
    const totalInterest1 = (new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalInterest));
    document.getElementById("totalInterest1").innerHTML = totalInterest1;


    var anneesListe = new Array(11);
    var mensualitepretListe = new Array(11);
    var mensualiteAssuranceListe = new Array(11);
    var coutTotalAssuranceListe = new Array(11);
    var coutTotalInteretListe = new Array(11);
    var mensualiteTotaleListe = new Array(11);  
    var coutProjetListe = new Array(11); 
    var cashflowListe = new Array(11); 


  var NBmois = (UIyears * 12);
for(var i= (UIyears - 5); i< UIyears + 6; i++)
    {
var anneesListelenght = anneesListe.push(i+ " ans");
var mensualitepretListelenght = mensualitepretListe.push(((UIamount - UIapport) * x * (parseFloat(UIinterest) / 100 / 12)) / (x-1));
var mensualiteAssuranceListelenght = mensualiteAssuranceListe.push((parseFloat(UIinterestassurance) / 100 / 12) * (UIamount - UIapport));
var coutTotalAssuranceListelenght = coutTotalAssuranceListe.push(monthlyPaymentAssurance * NBmois);
var coutTotalInteretListelenght = coutTotalInteretListe.push(monthlyPayment * NBmois - (UIamount - UIapport));
var mensualiteTotaleListelenght = mensualiteTotaleListe.push(monthlyPayment + monthlyPaymentAssurance);
var coutProjetListelenght = coutProjetListe.push(UIamount + totalPaymentAssurance + totalInterest);
var cashflowListelenght = cashflowListe.push(10858 - mensualitetotale);
}







// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

// Create chart instance
var chart = am4core.create("graphsimu", am4charts.XYChart);

chart.numberFormatter.intlLocales = "fr_FR";

// Data for both series
var data =  [
  { Durée: "10 ans", "Mensualité": 5400,  "Coût total du crédit": 49000},
  { Durée: "11 ans", "Mensualité": 5000, "Coût total du crédit": 54000 },
  { Durée: "12 ans", "Mensualité": 4600, "Coût total du crédit": 60000 },
  { Durée: "13 ans", "Mensualité": 4300, "Coût total du crédit": 70000 },
  { Durée: "14 ans", "Mensualité": 4000, "Coût total du crédit": 75000 },
  { Durée: "15 ans", "Mensualité": 3800, "Coût total du crédit": 84000 },
  { Durée: "16 ans", "Mensualité": 3650, "Coût total du crédit": 90000 },
  { Durée: "17 ans", "Mensualité": 3600, "Coût total du crédit": 98000 },
  { Durée: "18 ans", "Mensualité": 3400, "Coût total du crédit": 108000 },
  { Durée: "19 ans", "Mensualité": 3200, "Coût total du crédit": 115000 },
  { Durée: "20 ans", "Mensualité": 3000, "Coût total du crédit": 124000 },
];

/* Create axes */
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Durée";
categoryAxis.renderer.minGridDistance = 30;


/* Create value axis */
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var valueAxis2 = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis2.renderer.opposite = true;
valueAxis2.syncWithAxis = valueAxis;


var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryX = "Durée";
series.dataFields.valueY = "Mensualité";

series.columns.template.tooltipY = 0;
series.columns.template.strokeOpacity = 0;


var lineSeries = chart.series.push(new am4charts.LineSeries());
lineSeries.dataFields.valueY = "Coût total du crédit";
lineSeries.dataFields.categoryX = "Durée"; 
lineSeries.stroke = am4core.color("#880000");
lineSeries.strokeWidth = 3;
lineSeries.yAxis = valueAxis2;



var bullet = lineSeries.bullets.push(new am4charts.Bullet());

var circle = bullet.createChild(am4core.Circle);
circle.radius = 4;
circle.fill = am4core.color("#880000");
circle.strokeWidth = 3; 
chart.data = data;


/* Add a single HTML-based tooltip to first series */
series.tooltipText = `[bold] {Durée}[/]
----
Mensualité : [bold]{Mensualité} €[/]
Coût total du crédit : [bold]{Coût total du crédit} €[/]`;
series.tooltip.pointerOrientation = "vertical";





// as by default columns of the same series are of the same color, we add adapter which takes colors from chart.colors color set
series.columns.template.adapter.add("fill", function(fill, target) {
  return chart.colors.getIndex(target.dataItem.index);
});

/* Create a cursor */
chart.cursor = new am4charts.XYCursor();





  e.preventDefault();
}
const arr = [];
for(var i= (UIyears - 5); i< UIyears + 6; i++) {
    const entry = {
        'Durée': i+ ' ans',
        'Mensualité': monthlyPayment + monthlyPaymentAssurance, 
        'Coût total du crédit': UIamount + totalPaymentAssurance + totalInterest,
    };

    arr.push(entry);
}