You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Fortnite API响应中的指定内容

How to Remove Specific Unwanted Sections from Fortnite API BRStats Response in Node.js

I've written Node.js code to fetch BRStats data using the Fortnite API, and it successfully retrieves the response. Here's my working code:

const FortniteAPI = require("fortnite-api-com"); 
const config = { apikey: "REDACTED", language: "en", debug: true }; 
var Fortnite = new FortniteAPI(config); 
var name = "Ninja" 
Fortnite.BRStats({name: name, accountType: "epic", timeWindow:"lifetime", image: "none"}) 
.then(res => { console.log(res); }).catch(err => { console.log(err); });

Now I want to remove specific strikethrough-marked sections from the response. How can I achieve this?

Great job getting the API call working! To remove specific unwanted sections from the response, you have a few straightforward options based on your needs:


Option 1: Destructure the response to exclude unwanted fields

If you know exactly which fields you want to remove, use object destructuring to pull out the unwanted fields and keep the rest in a clean object. For example, if you want to remove unwantedField1 and unwantedNestedSection:

Fortnite.BRStats({name: name, accountType: "epic", timeWindow:"lifetime", image: "none"}) 
.then(res => {
  // Explicitly exclude unwanted fields, keep the rest
  const { unwantedField1, stats: { unwantedNestedSection, ...cleanedStats }, ...cleanedResponse } = res;
  cleanedResponse.stats = cleanedStats; // Reattach the cleaned nested stats
  console.log(cleanedResponse);
}).catch(err => { console.log(err); });

Option 2: Directly delete unwanted properties from the response

If you don't mind modifying the original response object, use the delete operator to strip out unwanted sections. This works for both top-level and nested fields:

Fortnite.BRStats({name: name, accountType: "epic", timeWindow:"lifetime", image: "none"}) 
.then(res => {
  // Delete top-level unwanted fields
  delete res.unwantedField1;
  // Delete nested unwanted fields
  delete res.stats.unwantedNestedSection;
  console.log(res); // Original object now has unwanted sections removed
}).catch(err => { console.log(err); });

Option 3: Create a new object with only desired fields

If you have a short list of fields you want to keep, explicitly build a new object with just those properties. This is the safest way to avoid accidentally retaining unwanted data:

Fortnite.BRStats({name: name, accountType: "epic", timeWindow:"lifetime", image: "none"}) 
.then(res => {
  const cleanedResponse = {
    username: res.username,
    platformInfo: res.platformInfo,
    lifetimeStats: res.lifetimeStats.filter(stat => !stat.isStrikethrough) // Filter out strikethrough stats if applicable
    // Add other specific fields you need here
  };
  console.log(cleanedResponse);
}).catch(err => { console.log(err); });

Just replace the placeholder field names in the examples with the actual keys of the sections you want to remove. If you're unsure about the response structure, log the full res object first to identify exactly which keys correspond to the strikethrough sections.

内容的提问来源于stack exchange,提问作者Lova

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 14:27:43